common business errors
$ npm install @nayotta/errors --save
// COMMONJS
const {
ToBeDoneError,
errors
} = require('@nayotta/errors')
// ESM
import {
ToBeDoneError,
errors
} from '@nayotta/errors'
async function do () {
throw new errors.ToBeDoneError('function do')
}
async function run () {
const res = await do().catch(err => err)
if (res instanceof Error) {
if (errors.isToBeDoneError(res)) {
console.log(res.name) // TBD_ERROR
console.log(res.message) // TBD: function a
console.log(res.code) // 403
console.log(res)
return
}
throw res
}
}
- name:
UNAUTHORIZATION_ERROR
- code:
401
- message:
unauthorization: <message>
- name:
NOT_FOUND_ERROR
- code:
404
- message:
not found: <name>
- name:
RESOURCE_NOT_FOUND_ERROR
- code:
404
- message:
resource not found: <resource>:<name> not found
- name:
RESOURCE_ALREADY_EXISTED_ERROR
- code:
400
- message:
resource already existed: <resource>:<name> already existed
- name:
INVALID_DATA_ERROR
- code:
400
- message:
invalid data: <name>
- name:
REQUIRED_ERROR
- code:
400
- message:
required: <name>
- name:
ARGUMENT_REQUIRED_ERROR
- code:
400
- message:
argument required: <name>
- name:
OPTION_REQUIRED_ERROR
- code:
400
- message:
option required: <name>
- name:
HEADER_REQUIRED_ERROR
- code:
400
- message:
header required: <name>
- name:
NOT_IMPLEMENTED_ERROR
- code:
403
- message:
not implemented: <name>
- name:
UNSUPPORTED_ERROR
- code:
403
- message:
unsupported: <name>
- name:
TYPE_SUPPORTED_ERROR
- code:
403
- message:
type supported: <type>:<name>
- name:
NOT_ALLOWED_ERROR
- code:
403
- message:
not allowed: <name>
- name:
TYPE_NOT_ALLOWED_ERROR
- code:
403
- message:
type not allowed: <type>:<name>
- name:
UNEXPECTED_ERROR
- code:
500
- message:
unexpected: <name>
- name:
TBD_ERROR
- code:
403
- message:
TBD: <name>