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
7 changes: 6 additions & 1 deletion packages/feathers/src/client/fetch.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { beforeAll, describe, it, expect } from 'vitest'
import { feathers } from '../index.js'
import { clientTests } from '../../fixtures/client.js'
import { NotAcceptable, NotFound, MethodNotAllowed } from '../errors.js'
import { NotAcceptable, NotFound, MethodNotAllowed, BadRequest } from '../errors.js'

import { getApp, createTestServer, TestServiceTypes, verify } from '../../fixtures/index.js'
import { fetchClient } from './index.js'
Expand Down Expand Up @@ -115,6 +115,11 @@ describe('fetch REST connector', function () {
await expect(() => service.internalMethod({})).rejects.toThrow(MethodNotAllowed)
})

it('.get with undefined and null erorrs', async () => {
await expect(() => service.get(undefined, {})).rejects.toThrow(BadRequest)
await expect(() => service.get(null, {})).rejects.toThrow(BadRequest)
})

it('supports async iterable streams', async () => {
const messages: any[] = []
const stream = await app.service('test').get('test')
Expand Down
6 changes: 3 additions & 3 deletions packages/feathers/src/client/fetch.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Params, Id, Query, NullableId } from '../declarations.js'
import { Unavailable, convert, errors } from '../errors.js'
import { BadRequest, Unavailable, convert, errors } from '../errors.js'
import { _, stripSlashes } from '../commons.js'
import { protectedProperties } from '../service.js'

Expand Down Expand Up @@ -175,8 +175,8 @@ export class FetchClient<T = any, D = Partial<T>, P extends Params = FetchClient
}

async _get(id: Id, params?: P) {
if (typeof id === 'undefined') {
throw new Error("id for 'get' can not be undefined")
if (id === null || typeof id === 'undefined') {
throw new BadRequest("id for 'get' can not be null of undefined")
}

return this.request(
Expand Down
Loading