Error Handling

Most of SDK's functions report their success or failure using an object with callbacks.

auth.passwordResetByMail('admin@example.com')
    .then(() => { 
        // This function will *not* be called in case of `Error`.
    })
    .catch((error) => {
        // This will be called.
        // error is an instance of DrupalError with details about the error.
        if (error.getErrorCode() === DrupalError.CONNECTION_FAILED) {
            alert("Uh oh, connection failed! please try again later.");
        }
        if (error.getErrorCode() === DrupalError.INVALID_JSON) {
            alert("Uh oh, recieved invalid response from server! \
            Please contact administrator.");
        }
    }) 







 


 




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

For a list of all possible DrupalError codes, check Error Codes, or see the DrupalError section of the JavaScript API DrupalError.