onFailure( )


A hook that is triggered on any error or rejected Promise from any of the wix-data operations.

The onFailure() hook is triggered whenever a wix-data operation or hook returns a rejected Promise or an error.

Method Declaration
Copy
function onFailure(error: Error, context: HookContext): Promise<object>;
Method Parameters
errorErrorRequired

The error that caused the failure.


contextHookContextRequired

Contextual information about the hook.

Returns
Return Type:Promise<object>
A hook triggered when a failure occurs
JavaScript
// In data.js export function myCollection_onFailure(error, context) { let hookError = error; // see below // handle error return ret; } /* * hookError: * * { * "message": "An item with _id [1234] already exists.", * "code": -409 * } */
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?