Search.../

onFailure( )

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

Description

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

Syntax

function onFailure(error: Error, context: HookContext): Promise<Object>

onFailure Parameters

NAME
TYPE
DESCRIPTION
error

Error

The error that caused the failure.

context

HookContext

Contextual information about the hook.

Returns

Fulfilled - Returning a fulfilled promise will result in a fulfilled data operation with the provided result. Rejected - Returning a rejected promise will result in returning a rejected promise to the caller of the data operation.

Return Type:

Promise<Object>

Was this helpful?

A hook triggered when a failure occurs

Code Example

Copy Code
1// In data.js
2
3export function myCollection_onFailure(error, context) {
4 let hookError = error; // see below
5
6 // handle error
7
8 return ret;
9}
10
11/*
12 * hookError:
13 *
14 * {
15 * "message": "An item with _id [1234] already exists.",
16 * "code": -409
17 * }
18 */