Registry Mirror
Skip to content

File tree

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

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -550,32 +550,15 @@ describe('standardHandler', () => {
550550
expect(error.code).toBe('INTERNAL_SERVER_ERROR')
551551
})
552552

553-
it('falls back to INTERNAL_SERVER_ERROR when encoding the error fails', async () => {
553+
it('throws when encoding the error fails', async () => {
554554
const encodingError = new RangeError('Maximum call stack size exceeded')
555555
client.mockRejectedValue(new ORPCError('BAD_REQUEST'))
556556

557557
codec.resolveProcedure.mockResolvedValue(makeResolved())
558-
codec.encodeError
559-
.mockRejectedValueOnce(encodingError)
560-
.mockResolvedValueOnce({ status: 500, headers: {}, body: 'internal' })
558+
codec.encodeError.mockRejectedValueOnce(encodingError)
561559

562-
const result = await handler.handle(makeRequest(), OPTIONS)
563-
564-
expect(result).toEqual({
565-
matched: true,
566-
response: { status: 500, headers: {}, body: 'internal' },
567-
})
568-
expect(codec.encodeError).toHaveBeenCalledTimes(2)
569-
expect(codec.encodeError).toHaveBeenLastCalledWith(
570-
expect.objectContaining({
571-
code: 'INTERNAL_SERVER_ERROR',
572-
data: undefined,
573-
cause: encodingError,
574-
}),
575-
expect.anything(),
576-
['ping'],
577-
OPTIONS,
578-
)
560+
await expect(handler.handle(makeRequest(), OPTIONS)).rejects.toBe(encodingError)
561+
expect(codec.encodeError).toHaveBeenCalledTimes(1)
579562
})
580563
})
581564

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

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -247,22 +247,10 @@ export class StandardHandler<T extends Context> {
247247
? error
248248
: await reconcileORPCError(procedure['~orpc'].errorMap, error)
249249

250-
let response: StandardResponse
251-
252-
try {
253-
response = await this.codec.encodeError(reconciled, procedure, path, {
254-
context,
255-
prefix,
256-
})
257-
} catch (cause) {
258-
recordSpanError(span, cause)
259-
response = await this.codec.encodeError(
260-
new ORPCError('INTERNAL_SERVER_ERROR', { cause }),
261-
procedure,
262-
path,
263-
{ context, prefix },
264-
)
265-
}
250+
const response = await this.codec.encodeError(reconciled, procedure, path, {
251+
context,
252+
prefix,
253+
})
266254

267255
return { matched: true, response }
268256
}

0 commit comments

Comments
 (0)