KR.onError()
KR.onError() allows to intercept errors before they appear.
Example of integration
An example for intercepting error messages:
https://github.com/lyra/rest-php-examples/blob/master/www/js_examples/jquery/minimalEmbeddedForm.onError.php#L70-L80
<script type="text/javascript"> $(document).ready(function() { KR.onError( function(event) { var code = event.errorCode; var message = event.errorMessage; var myMessage = code + ": " + message; try { /* if client answer exists, a refused transaction has been created */ /* it's not always the case. For example, if the form is empty, */ /* error is raised before transaction creation */
After that, error messages will automatically appear in the following element, if it is present:
<div id="customerror"></div>
When several errors are generated, they are merged into one single error. The children property will contain the details of all errors:
{ "errorCode": "CLIENT_300", "errorMessage": "Invalid form data", "children": [{ "errorCode": "CLIENT_301", "errorMessage": "Invalid card number", "field": "pan", (...) }, { "errorCode": "CLIENT_302", "errorMessage": "Invalid expiry date", "field": "expiryDate", (...) }, { "errorCode": "CLIENT_303", "errorMessage": "Invalid security code", "field": "securityCode", (...) }], "detailedErrorCode": null, "detailedErrorMessage": null, (...) }
For more information on errors, go to: Managing errors (JS client)