getErrors( ) method
- Last Updated: March 30, 2020
- 7 minute read
- OpenEdge
- Version 12.2
- Documentation
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
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.error event on the DataSource.Return type: Array of Object
Applies to: progress.data.JSDO class, table reference property (JSDO class)
Syntax
|
- 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— Astringvalue that describes the error depending on the error type. For more information, see thetypeproperty of thisObject.errorNum— Anumericvalue that returns an error number. This property is returned only if the error type isprogress.data.JSDO.APP_ERROR. For more information, see thetypeproperty of thisObject.id— Astringvalue 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 exceptprogress.data.JSDO.ERROR. If the error type isprogress.data.JSDO.APP_ERRORand is returned for a resource Read operation, theidproperty is never returned. If the error type isprogress.data.JSDO.DATA_ERRORand is returned for a resource CUD or Submit operation, theidproperty 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 thetypeproperty of thisObject.responseText— Astringvalue that contains the complete text of the HTTP response when the error type isprogress.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 thetypeproperty of thisObject.type— A numeric constant that identifies the origin of the error returned by thisObject: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 usingprodsproperties of the ProDataSet object in the response.For this error type, the
errorproperty returns an error string associated with the record object and this record object is identified by theidproperty. For a Submit operation, you can look up the corresponding before-image data for the record by invoking thegetId( )method on each element of the array returned by thejsrecordsproperty on the returned request object. You can also find the current data for the record in JSDO memory, if it exists, using the JSDOfindById( )method.Note: From an OpenEdge Data Object resource that supports before-imaging, this error type can be returned by setting both the ABLERRORandERROR-STRINGattributes 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
errorproperty returns an error message associated with the CRUD operation and theerrorNumproperty 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 theidproperty. You can also find the current data for the record in JSDO memory, if it exists, using the JSDOfindById( )method.Note: 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, orafterDelete), you can also return the record object identified by theidproperty as the value of thejsrecordproperty on the request object returned by the callback. - In the callback for an
afterSaveChangesevent on completion of a call tosaveChanges(false)(without Submit), you can identify the request object returned for each CUD operation by inspecting the value of thebatchproperty on the request object returned by the callback and compare this information with the information and data returned by theerrorproperty andidproperty for this error type. - In the callback for an
afterSaveChangesevent on completion of a call tosaveChanges(true)(with Submit), if this error type is returned, it is typically not returned with anidproperty, as the error type does not apply to a particular record object. - In the callback for an
afterFillevent (on completion of a Read operation invoked by a call tofill( )), theidproperty is never returned, as the error type does not apply to a particular record object.
Note: The same options that apply to callbacks forafterSaveChangesandafterFillevents also apply to corresponding callbacks registered to returned Promise objects.- In the callback for a CUD operation event (
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
errorproperty 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 theidproperty. You can find the current data for the record in JSDO memory, if it exists, using the JSDOfindById( )method.Note: From an OpenEdge Data Object resource, this error type can be returned using theRETURN ERRORstatement, or using a constructor or method of the built-in ABL class,Progress.Lang.AppError. For more information, see OpenEdge Development: ABL Reference.Note: OpenEdge Data Object Services using the WebHandler service provider can return multipleRETVALerrors per operation in the array returned bygetErrors( ), including one for the operation itself and one for each routine on the operation call stack. AnyRETVALerror, regardless of the Data Object Service, can be followed by one or moreAPP_ERRORerrors.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
errorproperty returns an HTTP error string in the following form:HTTP error-number error-textWhere:
- 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
responseTextproperty 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
([]).
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.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( ).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:
|
'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