Skip to content

Commit

Permalink
fix(errors): Allows to pass no error message (#2794)
Browse files Browse the repository at this point in the history
  • Loading branch information
daffl authored Oct 12, 2022
1 parent d3ee41e commit f3ddab6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/errors/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
5 changes: 5 additions & 0 deletions packages/errors/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit f3ddab6

Please sign in to comment.