Skip to content

Commit f3ddab6

Browse files
authored
fix(errors): Allows to pass no error message (#2794)
1 parent d3ee41e commit f3ddab6

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

packages/errors/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export interface FeathersErrorJSON {
88
}
99

1010
export type DynamicError = Error & { [key: string]: any }
11-
export type ErrorMessage = string | DynamicError | { [key: string]: any } | any[]
11+
export type ErrorMessage = null | string | DynamicError | { [key: string]: any } | any[]
1212

1313
interface ErrorProperties extends Omit<FeathersErrorJSON, 'message'> {
1414
type: string
@@ -33,7 +33,7 @@ export class FeathersError extends Error {
3333
if (Array.isArray(_data)) {
3434
properties.data = _data
3535
} else if (typeof err === 'object' || _data !== undefined) {
36-
const { message, errors, ...rest } = typeof err === 'object' ? err : _data
36+
const { message, errors, ...rest } = err !== null && typeof err === 'object' ? err : _data
3737

3838
msg = message || msg
3939
properties.errors = errors

packages/errors/test/index.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,11 @@ describe('@feathersjs/errors', () => {
345345
assert.deepStrictEqual(error.data, [{ hello: 'world' }])
346346
})
347347

348+
it('can be instantiated with `null` (#2789)', () => {
349+
const err = new errors.BadRequest(null, {})
350+
assert.strictEqual(err.message, 'Error')
351+
})
352+
348353
it('has proper stack trace (#78)', () => {
349354
try {
350355
throw new errors.NotFound('Not the error you are looking for')

0 commit comments

Comments
 (0)