mirror of
https://github.com/feathersjs/feathers.git
synced 2026-02-01 17:37:38 +00:00
fix(errors): Allows to pass no error message (#2794)
This commit is contained in:
parent
d3ee41e27b
commit
f3ddab637e
@ -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
|
||||
|
||||
@ -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')
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user