Jsonql js error classes use across the projects
This module exports a bunch of custom Error class for developer to use.
When the server side throw error, the client side will try to throw exactly
the same error and as developer you can clearly understand what is happening.
``js
// bunch of setup
client.query.getSomething(1)
.then(result => / do your thing /)
.catch(err => {
if (err instanceof JsonqlValidateError) {
// update your UI to show the validation error
} else if (err instanceof Jsonql500Error) {
// ooops the server is down
} else {
// then this will NOT be an error throw from jsonql system
}
})
`
- Jsonql406Error
- Jsonql500Error
- JsonqlAuthorisationError
- JsonqlContractAuthError
- JsonqlResolverAppError
- JsonqlResolverNotFoundError
- JsonqlCheckerError
- JsonqlEnumError
- JsonqlTypeError
- JsonqlValidationError
- JsonqlError
- JsonqlServerError
This package also export several useful help functions, and we use this
across multiple jsonql modules.
Get the error class name by it's status code, use on client side
arguments:
- statusCode {number} the status code
- contract {boolean} if this is from the contract hack
returns:
- {string} the name of the error class
Check the resolver return result for error, use on client side
arguments:
- result {object} after we call a resolver and check the result if it's contain an error
returns:
- {object} if its passed then just return the result or throw a new error
Repackage the error throw from the application
arguments:
- e {object} the error we catch
returns:
- throw the correct structure in our own error classes
Compare a list of errors class with the error we catch, then get it's name
arguments:
- errs {array} list of error classes
- e {object} the error object we captured
returns:
- {string} the name of the error class or unknown if it's not ours
There are two constants export from this module as well
- JSONQL_ERRORS_INFO gives you the version numberUNKNOWN_ERROR
- this is to use with the getErrorNameByInstance when we could not determine what type of error it is.
This is a standalone error type for use in a different type of module.
This is not export from the default export path, therefore you need to import it directly:
`js``
import GeneralError from 'jsonql-errors/general'
---
ISC (c) 2019 NEWBRAN LTD / TO1SOURCE.CN