JSDO properties, methods, and events reference : getErrors( ) method
  

getErrors( ) method

Note: Updated to support all possible types of error returns in Progress Data Objects 4.3 or later.
Returns an array of errors from the most recent invocation of Create, Read, Update, Delete, or Submit operations (CRUD or Submit) that you have invoked by calling the JSDO fill( ) or saveChanges( ) method on a Data Object resource.
You can call this method on a single JSDO table reference at any point after fill( ) or saveChanges( ) is invoked, typically in a callback function executed for each fired JSDO after* event or for any Promise object returned by fill( ) or saveChanges( ). The errors returned from this method apply either to the data in the single JSDO table that is involved in the invoked operation or operations, or to the web or application servers that handle the requests. These errors are cleared with the next invocation of fill( ) or saveChanges( ) on the same resource, no matter the setting of the JSDO autoApplyChanges property.
This method allows you to access error information returned for every possible error, whether it is generated by:
*Routines on the application server that implement the CRUD or Submit operations on a given Data Object resource, and whether or not the resource supports before-imaging
*The application server that implements the specified Data Object Service, regardless of the Data Object resource and its executed CRUD or Submit operations
*The specified web server or web application, regardless of the Data Object Service you are accessing
Note: Using this method, you have no need to inspect error information returned by either the response property or the xhr property (XMLHttpRequest object) in any request object returned by fill( ) or saveChanges( ), or the error string returned by the getErrorString( ) method called on a JSRecord object.
Note: If you have a reference to the JSDO used to instantiate the JSDO dialect of the Kendo UI DataSource, you can also call this method in any callback function registered for the error event on the DataSource. For more information, see Using the JSDO dialect of the Kendo UI DataSource .
Return type: Array of Object
Applies to: progress.data.JSDO class, table reference property (JSDO class)

Syntax

jsdo-ref.getErrors ( )
jsdo-ref.table-ref.getErrors ( )
jsdo-ref
A reference to the JSDO. You can call the method on jsdo-ref if the JSDO has only a single table reference.
table-ref
A table reference on the JSDO.

Response

The array returned by this method contains errors associated with the resource operation or operations that were invoked by the most recent call to fill( ) or saveChanges( ). Each element of the array returned by this method is an Object that corresponds to a single type of error returned by an operation on the resource and contains the following properties:
*error — A string value that describes the error depending on the error type. For more information, see the type property of this Object.
*errorNum — A numeric value that returns an error number. This property is returned only if the error type is progress.data.JSDO.APP_ERROR. For more information, see the type property of this Object.
Note: Applies to Progress Data Objects Version 4.3 or later.
*id — A string value containing the internal ID of the record object on which the resource operation has returned the error. This property can be returned, if appropriate, for any error type except progress.data.JSDO.ERROR. If the error type is progress.data.JSDO.APP_ERROR and is returned for a resource Read operation, the id property is never returned. If the error type is progress.data.JSDO.DATA_ERROR and is returned for a resource CUD or Submit operation, the id property is always returned. How you can use this value to return information about the record object depends on the error type. For more information, see the type property of this Object.
*responseText — A string value that contains the complete text of the HTTP response when the error type is progress.data.JSDO.ERROR. For example, this can be the HTML text of an error page displayed by the browser, which you can also display using the browser's web inspector. For more information, see the type property of this Object.
Note: Applies to Progress Data Objects Version 4.3 or later.
*type — A numeric constant that identifies the origin of the error returned by this Object:
Note: Applies to Progress Data Objects Version 4.3 or later.
*progress.data.JSDO.DATA_ERROR — An error returned for a CUD or Submit operation on a record object in a resource with before-image data. The response for this type of error uses HTTP status code 200 OK, and the error information is returned using prods properties of the ProDataSet object in the response.
For this error type, the error property returns an error string associated with the record object and this record object is identified by the id property. For a Submit operation, you can look up the corresponding before-image data for the record by invoking the getId( ) method on each element of the array returned by the jsrecords property on the returned request object. You can also find the current data for the record in JSDO memory, if it exists, using the JSDO findById( ) method.
From an OpenEdge Data Object resource that supports before-imaging, this error type can be returned by setting both the ABL ERROR and ERROR-STRING attributes on a buffer object handle set to the corresponding record in the corresponding ABL temp-table. For more information on these attributes, see OpenEdge Development: ABL Reference and OpenEdge Development: ProDataSets.
*progress.data.JSDO.APP_ERROR — An HTTP 4xx or 5xx error returned for a CRUD operation on a resource without before-image data (and sometimes also for a CUD or Submit operation with before-image data).
For this error type, the error property returns an error message associated with the CRUD operation and the errorNum property returns the numeric value of the error number. For a CUD operation, the associated record object in the resource can also be identified using the value of the id property. You can also find the current data for the record in JSDO memory, if it exists, using the JSDO findById( ) method.
From an OpenEdge Data Object resource, this error type can be returned using a constructor or method of the built-in ABL class, Progress.Lang.AppError. For more information, see OpenEdge Development: ABL Reference.
Other properties are available to interpret this information, depending on the resource operation and event callback where getErrors( ) is called, and include:
*In the callback for a CUD operation event (afterCreate, afterUpdate, or afterDelete), you can also return the record object identified by the id property as the value of the jsrecord property on the request object returned by the callback.
*In the callback for an afterSaveChanges event on completion of a call to saveChanges(false) (without Submit), you can identify the request object returned for each CUD operation by inspecting the value of the batch property on the request object returned by the callback and compare this information with the information and data returned by the error property and id property for this error type.
*In the callback for an afterSaveChanges event on completion of a call to saveChanges(true) (with Submit), if this error type is returned, it is typically not returned with an id property, as the error type does not apply to a particular record object.
*In the callback for an afterFill event (on completion of a Read operation invoked by a call to fill( )), the id property is never returned, as the error type does not apply to a particular record object.
The same options that apply to callbacks for afterSaveChanges and afterFill events also apply to corresponding callbacks registered to returned Promise objects.
*progress.data.JSDO.RETVAL — An HTTP 4xx or 5xx error that returns a CRUD operation return value on a resource without before-image data (and sometimes also for a CUD or Submit operation with before-image data).
For this error type, the error property returns the CRUD operation return value as a string. For a CUD operation, the associated record object in the resource can also be identified by the id property. You can find the current data for the record in JSDO memory, if it exists, using the JSDO findById( ) method.
From an OpenEdge Data Object resource, this error type can be returned using the RETURN ERROR statement, or using a constructor or method of the built-in ABL class, Progress.Lang.AppError. For more information, see OpenEdge Development: ABL Reference.
OpenEdge Data Object Services using the WebHandler service provider can return multiple RETVAL errors per operation in the array returned by getErrors( ), including one for the operation itself and one for each routine on the operation call stack. Any RETVAL error, regardless of the Data Object Service, can be followed by one or more APP_ERROR errors.
*progress.data.JSDO.ERROR — The text of a JavaScript exception or a web server HTTP 4xx or 5xx error returned without regard to any particular CRUD or Submit operation that was invoked.
For an HTTP 4xx or 5xx error, the error property returns an HTTP error string in the following form:
HTTP error-number error-text
Where:
*error-number is the HTTP 4xx or 5xx numeric value. For example, 500.
*error-text is a brief description of the web server error. For more information, you can inspect the value of the responseText property or view the associated web page displayed by the browser web inspector.
If there are no errors for the operation and resource on which getErrors( ) is called, this method returns an empty array ([]).
Note: For a CUD or Submit operation on a resource with before-image data that can return a DATA_ERROR, APP_ERROR, or RETVAL error, the operation can return either a DATA_ERROR error or it can return a RETVAL error followed by one or more APP_ERROR errors, but not both.
Note: If the method returns any errors, the JSDO also returns the request object for the operation with its success property set to false. This is also the value of the success parameter passed to any callback function subscribed to a JSDO after* event or passed to any callback function registered by a JSDO Promise object returned by fill( ) or saveChanges( ).
Note: This method does not track errors returned by an Invoke operation.

Example

The following code fragment shows the getErrors( ) method invoked on the JSDO in the callback function (onAfterSaveChanges) that is subscribed to the JSDO afterSaveChanges event after invoking a Submit operation (saveChanges(true)) on the JSDO OpenEdge ProDataSet resource named 'Customer' with a ttCustomer table, and which supports both before-imaging and the Submit operation:
dsCustomer = new progress.data.JSDO({ name: 'Customer' });
dsCustomer.subscribe('afterFill', onAfterFillCustomers, this);
dsCustomer.subscribe('afterSaveChanges', onAfterSaveChanges, this);
. . .

dsCustomer.saveChanges(true); /* Invoke Submit */
. . .

function onAfterSaveChanges(jsdo, success, request) {
var errors;
var errorType;
console.log("DEBUG: AfterSaveChanges: " + success + " errors: " + errors.length);

if (!success) {
errors = jsdo.ttCustomer.getErrors();
for (var i = 0; i < errors.length; i++) {
switch(errors[i].type) {
case progress.data.JSDO.DATA_ERROR:
errorType = "Server Data Error: ";
break;
case progress.data.JSDO.RETVAL:
errorType = "Server App Return Value: ";
break;
case progress.data.JSDO.APP_ERROR:
errorType = "Server App Error #" + errors[i].errorNum + ": ";
break;
case progress.data.JSDO.ERROR:
errorType = "Server General Error: ";
break;
case default:
errorType = null; // Unexpected errorType value
break;
}
if (errorType) {
console.log("ERROR: " + errorType + errors[i].error);
if (errors[i].id) { /* error with record object */
console.log("RECORD ID: " + errors[i].id);
/* Possibly log record change information based on data error
record object found in the request.jsrecords using getId()
*/
}
if (errors[i].responseText) {
console.log("HTTP FULL TEXT: "
+ errors[i].responseText);
}
}
else { /* unexpected errorType */
console.log("UNEXPECTED ERROR TYPE: "
+ errors[i].type);
}
}
}
}
Note: If the 'Customer' resource supports before-imaging but does not support a Submit operation, this same code fragment continues to work by changing the saveChanges( ) method call from saveChanges(true) to saveChanges(false) (or simply, saveChanges()). However, in this case, there is no request.jsrecords property available for access. Instead, you might locate information on the record and its record change operation by inspecting the request.batch property.

See also:

autoApplyChanges property, batch property, getErrorString( ) method, fill( ) method, findById( ) method, getId( ) method, jsrecord property, progress.data.JSRecord class, response property, saveChanges( ) method, xhr property