Error Reporting

The Commerce Server Business Desk Framework provides error reporting routines for both client-side and server-side script. These routines fall into the following categories:

  • Formatting routines that are used to construct an HTML table that shows the details of one of several categories of errors.

  • A routine used to set error information in server code that will be displayed on the client when the task bar is inserted in the page.

  • Display routines that result in an error dialog box to be displayed to the Business Desk user.

  • A routine that is used to fetch friendly error strings based on a more terse error string ID.

This topic contains:

  • Server-Side Error Routines. Describes the routines supplied by the Framework for formatting and displaying errors within server-side script.

  • Client-Side Error Routines. Describes the routines supplied by the Framework for formatting and displaying errors within client-side script.

  • Error Routine Examples. Provides a number of examples, showing how the error reporting routines can be combined to report different types of errors.

Server-Side Error Routines

There are four server-side routines for formatting error details, one each for formatting the following types of errors: ADO errors, ASP errors, XML parsing errors, and VBScript errors. For more information about server-side error routines, see:

sGetADOError (server-side) sGetScriptError (server-side)
sGetASPError (server-side) sGetXMLError (server-side)

The routine SetError is provided for logging an error in server-side script for eventual display to the Business Desk user. The error information is stored in the ASP Session object and is automatically retrieved and displayed to the user the next time one of the taskbar routines (InsertTaskBar or InsertEditTaskBar) is invoked. For more information about the SetError routine, see SetError (server-side).

Server-side errors are also logged to the Windows NT Application Event Log under the Commerce Server 2000 source.

The routine sGetErrorById is provided to allow the error summary strings stored in the global MessageManager object to be retrieved based on more cryptic, non-localized identifier strings. For more information about the sGetErrorById routine, see sGetErrorById (server-side).

Client-Side Error Routines

There are two client-side routines for formatting error details, one for formatting the details of XML parsing errors, and one for formatting the details of VBScript errors. For more information about client-side error routines, see:

sGetScriptError (client-side) sGetXMLError (client-side)

The routine ShowErrorDialog is provided for displaying an error dialog box to the Business Desk user from client-side script. For more information about the ShowErrorDialog routine, see ShowErrorDlg (client-side).

The error dialog is displayed immediately, and is modal. The detail formatting routines are called within the parameter list of ShowErrorDialog, providing the detail string via their return value.

Error Routine Examples

The following examples show various ways in which the formatting and display routines can be combined to report different types of errors.

The following server-side example shows a call to SetError where the dialog box title is referenced through a localizable string constant, the summary string is looked up using sGetErrorById, and the error details are retrieved using the ASP getLastError method. This example displays an error dialog box with the critical icon.

The call to InsertTaskBar following the call to SetError results in a call to the client-side routine ShowErrorDialog, passing the SetError parameters that were temporarily stored in the Session object.

<%
Call SetError(L_ASP_ERROR_TITLE, _
              SGetErrorById("CS4ERR_ASP_ERROR"), _
              sGetASPError(Server.getLastError), _
              ERROR_ICON_CRITICAL)

Call InsertTaskBar(L_PAGETITLE_TEXT, L_STATUS_TEXT)
%>

The following client-side example shows a call to ShowErrorDialog where the dialog box title and summary strings are referenced through localizable string constants and the error details are contained in the Visual Basic global Err object. This example displays an error dialog box with the question icon.

<SCRIPT LANGUAGE='VBScript'>
Call ShowErrorDialog(L_VB_SCRIPT_ERROR_TITLE, _
                     L_VB_SCRIPT_ERROR_MESSAGE, _
                     sGetScriptError(Err), _
                     ERROR_ICON_QUESTION)
</SCRIPT>

The following client-side example shows a call to ShowErrorDialog where the dialog box title and summary strings are referenced through localizable string constants and the error details are retrieved using the XML Document Object Model (DOM) parseError method (assumes a reference to an XML document is contained in the variable xmlDoc). This example displays an error dialog box with the critical icon.

<SCRIPT LANGUAGE='VBScript'>
Call ShowErrorDialog(L_XML_PARSE_ERROR_TITLE, _
                     L_XML_PARSE_ERROR_MESSAGE, _
                     sGetXMLError(xmlDoc.parseError), _
                     ERROR_ICON_CRITICAL)
</SCRIPT>

The following client-side example shows a call to ShowErrorDialog where the dialog box title is referenced through a localizable string constant, the summary string is looked up in server-side script, and the error details are retrieved in server-side script using the ASP getLastError method. This example displays an error dialog box with the alert icon.

<SCRIPT LANGUAGE='VBScript'>
Call ShowErrorDialog(L_ASP_ERROR_TITLE, _
                     "<%= sGetErrorById("CS4ERR_ASP_ERROR") %>", _
                     "<%= sGetASPError(Server.getLastError()) %>", _
                     ERROR_ICON_ALERT)
</SCRIPT>

The following client-side example shows a call to ShowErrorDialog where the dialog box title and summary strings are referenced through localizable string constants and the error details are retrieved in server-side script using the first error object in the errors collection of an Active Data Objects (ADO) Connection object (assumes a reference to an ADO Connection object is contained in the variable oConn, and that that object contains at least one valid error object). This example displays an error dialog box with the information icon.

<SCRIPT LANGUAGE='VBScript'>
Call ShowErrorDialog(L_ADO_ERROR_TITLE, _
                     L_ADO_ERROR_MESSAGE, _
                     "<%= sGetADOError(oConn.errors.error(0)) %>", _
                     ERROR_ICON_INFORMATION)
</SCRIPT>

The following client-side example shows a call to ShowErrorDialog that displays a dialog box with the default title, summary string, and icon. No details button appears in the dialog box.

<SCRIPT LANGUAGE='VBScript'>
Call ShowErrorDialog("", "", "", "")
</SCRIPT>


All rights reserved.