@foxy.io/sdk
Version:
Universal SDK for a full server-side and a limited in-browser access to Foxy hAPI.
34 lines (33 loc) • 1.87 kB
JavaScript
import v8n from 'v8n';
/**
* Base error class for all authentication-related errors in
* the APIs that can be used both server and client-side. If you're
* building your own API client with our SDK, you should consider using
* this class for similar purposes.
*/
export class AuthError extends Error {
constructor(params) {
AuthError.v8n.constructor.check(params);
super(`authentication failed with code ${params.code}`);
this.originalError = params.originalError;
this.code = params.code;
}
}
/** Credentials are valid, but the session can be created only after changing the current password. This usually happens after a server-side password reset has been initiated for security reasons. */
AuthError.NEW_PASSWORD_REQUIRED = 'NEW_PASSWORD_REQUIRED';
/** Credentials are valid, but the new password provided in response to the `NEW_PASSWORD_REQUIRED` error doesn't meet the security requirements. */
AuthError.INVALID_NEW_PASSWORD = 'INVALID_NEW_PASSWORD';
/** Credentials are invalid. That could mean empty or invalid email or password or otherwise incorrect auth data. */
AuthError.UNAUTHORIZED = 'UNAUTHORIZED';
/** Provided form data is invalid, e.g. email is too long or captcha is expired. */
AuthError.INVALID_FORM = 'INVALID_FORM';
/** Provided email is already taken. Applies to customer registration only. */
AuthError.UNAVAILABLE = 'UNAVAILABLE';
/** Any other or internal error that interrupted authentication. */
AuthError.UNKNOWN = 'UNKNOWN';
/** Available class member validators. */
AuthError.v8n = {
constructor: v8n().schema({
code: v8n().passesAnyOf(v8n().exact(AuthError.NEW_PASSWORD_REQUIRED), v8n().exact(AuthError.INVALID_NEW_PASSWORD), v8n().exact(AuthError.UNAUTHORIZED), v8n().exact(AuthError.INVALID_FORM), v8n().exact(AuthError.UNAVAILABLE), v8n().exact(AuthError.UNKNOWN)),
}),
};