Registry Mirror
Skip to content

File tree

‎packages/server/src/adapters/standard/handler.test.ts‎

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ describe('standardHandler', () => {
214214
})
215215
})
216216

217-
it('on error encoding failure, falls back to INTERNAL_SERVER_ERROR', async () => {
217+
it('on error encoding failure, throws', async () => {
218218
matcher.match.mockResolvedValue({
219219
path: ['ping'],
220220
procedure: ping,
@@ -231,22 +231,14 @@ describe('standardHandler', () => {
231231
codec.encodeError.mockImplementationOnce(() => {
232232
throw encodeError
233233
})
234-
codec.encodeError.mockReturnValueOnce(response)
235234

236-
const result = await handler.handle(request, {
235+
await expect(handler.handle(request, {
237236
context: { db: 'postgres' },
238237
prefix: '/api/v1',
239-
})
238+
})).rejects.toBe(encodeError)
240239

241-
expect(result).toEqual({ matched: true, response })
242-
243-
expect(codec.encodeError).toHaveBeenCalledTimes(2)
244-
expect(codec.encodeError).toHaveBeenNthCalledWith(1, error)
245-
expect(codec.encodeError).toHaveBeenNthCalledWith(2, expect.objectContaining({
246-
code: 'INTERNAL_SERVER_ERROR',
247-
data: undefined,
248-
cause: encodeError,
249-
}))
240+
expect(codec.encodeError).toHaveBeenCalledTimes(1)
241+
expect(codec.encodeError).toHaveBeenCalledWith(error)
250242
})
251243

252244
it('on decode error, converts to BAD_REQUEST before interceptors see it', async () => {

‎packages/server/src/adapters/standard/handler.ts‎

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -173,15 +173,7 @@ export class StandardHandler<T extends Context> {
173173

174174
const error = toORPCError(e)
175175

176-
let response: StandardResponse
177-
178-
try {
179-
response = this.codec.encodeError(error)
180-
}
181-
catch (cause) {
182-
setSpanError(span, cause)
183-
response = this.codec.encodeError(new ORPCError('INTERNAL_SERVER_ERROR', { cause }))
184-
}
176+
const response = this.codec.encodeError(error)
185177

186178
return {
187179
matched: true,

0 commit comments

Comments
 (0)