fix(errors): Allows to pass no error message (#2794)

This commit is contained in:
David Luecke 2022-10-12 10:31:43 -07:00 committed by GitHub
parent d3ee41e27b
commit f3ddab637e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 2 deletions

View File

@ -8,7 +8,7 @@ export interface FeathersErrorJSON {
}
export type DynamicError = Error & { [key: string]: any }
export type ErrorMessage = string | DynamicError | { [key: string]: any } | any[]
export type ErrorMessage = null | string | DynamicError | { [key: string]: any } | any[]
interface ErrorProperties extends Omit<FeathersErrorJSON, 'message'> {
type: string
@ -33,7 +33,7 @@ export class FeathersError extends Error {
if (Array.isArray(_data)) {
properties.data = _data
} else if (typeof err === 'object' || _data !== undefined) {
const { message, errors, ...rest } = typeof err === 'object' ? err : _data
const { message, errors, ...rest } = err !== null && typeof err === 'object' ? err : _data
msg = message || msg
properties.errors = errors

View File

@ -345,6 +345,11 @@ describe('@feathersjs/errors', () => {
assert.deepStrictEqual(error.data, [{ hello: 'world' }])
})
it('can be instantiated with `null` (#2789)', () => {
const err = new errors.BadRequest(null, {})
assert.strictEqual(err.message, 'Error')
})
it('has proper stack trace (#78)', () => {
try {
throw new errors.NotFound('Not the error you are looking for')