Support custom error messages from custom DB scripts
For example, /dbconnections/signup returns an error like this when returning new ValidationError('invalid_user', 'error message') from a signup script:
{
"message": "error message",
"code": "invalid_user",
"description": "error message",
"fromSandbox": true
}
Currently Lock just shows "There was an error when processing the signup".
I'm running on same issue from lock and from API calls (/dbconnections/signup) who returns HTTP ERROR 400 - BAD REQUEST
Hi! I'm sorry about the copy/paste message, but I'm cleaning up some stale issues. 🗑 It's been a while since this issue was opened. Are you still having this issue with the latest version? If so, please reopen it with some repro steps so we can help!
Could you please reopen this ticket? I would really like to have custom error messages propagated to the client.
First of all, the documentation for database scripts [1] should be updated. Right now it's not clear what the errors are used for.
- What are the error codes used for?
- What error codes are supported?
I currently have a custom database script that throws ValidationError in some cases, e.g. callback(new ValidationError('user-not-active', 'You must accept the invitation from us before proceeding')). This scripts runs on "Get User", which is trigged when a user submits a new password via a password reset link. However, the error message is not propagated back to the client. We're using Auth0 Lock for web and the error message to the client is a generic one: "We're sorry, something went wrong when requesting the password change". We're using Auth0 Lock 11.3.0 for web.
Repro:
- Create a custom database connection
- Enable "Import Users to Auth0"
- Setup a Auth0 Lock (for web) to use your database connection
- Update script for "Get User" with [2]
- Click Don't remember your password? in the Auth0 Lock widget
- Type email error@your_domain.com and click "SEND EMAIL"
- Error message "We're sorry, something went wrong when requesting the password change." appears
Using new Error or new ValidationError gives me the same result.
[1] https://auth0.com/docs/connections/database/custom-db
[2] Script for "Get User":
function getByEmail (email, callback) {
if (email === 'success@your_domain.com') {
var profile = {
user_id: '123456',
email: email,
email_verified: true,
phone_number: '+467012345678',
phone_verified: false,
name: 'Jane Doe',
given_name: 'Jane',
family_name: 'Doe',
};
callback(null, profile);
}
else if (email === 'error@your_domain.com') {
callback(new ValidationError('user-not-active', 'You must accept the invitation from us before proceeding'));
}
callback(null);
}
@roku6185 this is already supported:
lock.show({
languageDictionary: {
error: {
forgotPassword: {
'user-not-active': 'your custom error message'
}
}
}
});

Oh, I see. I will give it a try. Thanks :+1:
But I still think the documentation should be updated. Reading about customizing error messages in Auth0 Lock [1] gives me the impression that only predefined error messages can be customized. There is nothing about being able to add new error codes. The same thing goes for [2].
[1] https://auth0.com/docs/libraries/lock/v11/customizing-error-messages [2] https://auth0.com/docs/connections/database/custom-db
I just added a PR to better explain this scenario: https://github.com/auth0/docs/pull/5944
Is it working for all custom-db scripts?
I followed your PR and use this code in my login script:
return callback(new ValidationError('custom-error-code', 'Some custom message'))
And updated my language dictionary:
languageDictionary: {
error: {
login: {
'custom-error-code': 'your custom error message'
}
}
},
(I'm not really sure the "login" key is the good one, I guessed it).
The response I receive is (while looking at the network):
{"error":"access_denied","error_description":"Some custom message"}
And the error I intercept with lock.on('authorization_error' is give me this result:
{
code : "invalid_user_password",
description: undefined,
error: "invalid_user_password"
}
So at least the description is partially propagated, but it doesn't look like the error code is. What do I miss?
@vincentdesmares For login scenarios, I believe we only respond with error codes that are in the OIDC spec. Please reach out to our amazing support team at https://support.auth0.com so they can clarify this situation.
I understand that. I will find another way to handle my use case.
I still have some doubt on the error description, on the normalizeError function (helper.js) there is this code snippet:
if (error.error === 'access_denied') {
return {
code: 'invalid_user_password',
error: 'invalid_user_password',
description: error.description
};
}
error.description does not exists as the server always send error_description instead. I guess this should be:
description: error.description || error.error_description
Right?
Nope, auth0.js already normalizes the response errors here: https://github.com/auth0/auth0.js/blob/master/src/helper/response-handler.js#L46
I got it 🎊 Thank you for your quick support!
You fixed it on the Feb 15th: https://github.com/auth0/auth0.js/commit/63c7486414d8119125a6ef6276c73d8305688e57#diff-d11e52f1fb3694d91e615158b2f418ec
Upgrading to the last version of auth0-lock solved it :)
awesome! 🎉