orpc-customizing-error-response
Customize the error response format in oRPC OpenAPI.
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
메뉴
Customize the error response format in oRPC OpenAPI.
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
SOC 직업 분류 기준
Quick reference for Better Notify configuration, patterns, and common gotchas
Interactive setup wizard for adding Better Notify to a TypeScript/JavaScript project
Context and API guidance for Better Notify — end-to-end typed notification infrastructure for Node.js
Seamlessly use AI SDK inside your oRPC projects without any extra overhead.
Use oRPC inside an Astro project.
Functions to encode and decode base64url strings (URL-safe variant of base64).
| name | oRPC Customizing Error Response |
| description | Customize the error response format in oRPC OpenAPI. |
| license | MIT |
| metadata | {"author":"Ali Torki","homepage":"https://github.com/ali-master","version":"1.0.0"} |
By default, OpenAPIHandler, OpenAPIGenerator, and OpenAPILink share the same error response format. You can customize one, some, or all of them.
OpenAPIHandlerUse customErrorResponseBodyEncoder:
const handler = new OpenAPIHandler(router, {
customErrorResponseBodyEncoder(error) {
return error.toJSON()
},
})
Return
nullorundefinedto fallback to the default behavior.
OpenAPIGeneratorCustomize the error response format with customErrorResponseBodySchema:
const generator = new OpenAPIGenerator()
const spec = await generator.generate(router, {
customErrorResponseBodySchema: (definedErrorDefinitions, status) => {
const result: Record<any, any> = {
oneOf: [
{
type: 'object',
properties: {
defined: { const: false },
code: { type: 'string' },
status: { type: 'number' },
message: { type: 'string' },
data: {},
},
required: ['defined', 'code', 'status', 'message'],
},
],
}
for (const [code, defaultMessage, dataRequired, dataSchema] of definedErrorDefinitions) {
result.oneOf.push({
type: 'object',
properties: {
defined: { const: true },
code: { const: code },
status: { const: status },
message: { type: 'string', default: defaultMessage },
data: dataSchema,
},
required: dataRequired
? ['defined', 'code', 'status', 'message', 'data']
: ['defined', 'code', 'status', 'message'],
})
}
return result
}
})
OpenAPILinkWhen your backend uses a custom error format, parse it to an ORPCError:
const link = OpenAPILink(contract, {
customErrorResponseBodyDecoder: (body, response) => {
if (isORPCErrorJson(body)) {
return createORPCErrorFromJson(body)
}
return null // default behavior
}
})