Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix(errors): Allows to pass no error message
  • Loading branch information
daffl committed Oct 12, 2022
commit 8712c3e832f348e26c3dd51f44d985bf4cb4a1bf
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