Target repo :ekoen-backend, Route Error Documentation
Use this skill when adding or updating error responses in TSOA controllers under app/rpc/v2/controller/**.
Goal
If a controller method can throw a defined error from app/util/errors/index.ts, document it with TSOA @Response using HttpErrorRes (or HttpErrorRes[] for multiple errors).
Quick Flow
- Identify the controller method(s) that can throw errors (directly or via use case/service).
- Locate the matching error definitions in
app/util/errors/index.ts(namespace inekErr). - Import
HttpErrorResandekErrinto the controller file. - Add
@Responsedecorators above the route method:- Single error:
@Response<HttpErrorRes>('422', error.message, error) - Multiple errors:
@Response<HttpErrorRes[]>('409', 'failed, one of list', [errorA, errorB])
- Single error:
- Use
toHttpResBody()to supply the error examples, consistent with existing controllers.
Controller Example Pattern
import { Response } from 'tsoa';
import { ekErr, type HttpErrorRes } from 'app/util';
const exampleA = new ekErr.EkoEN.SomeError().toHttpResBody();
const exampleB = new ekErr.Api.InvalidArgs().toHttpResBody();
@Response<HttpErrorRes>('422', exampleB.message, exampleB)
@Response<HttpErrorRes[]>('409', 'failed, one of list', [exampleA])
Notes
- Keep error documentation in the controller (presentation layer).
- Do not add new error definitions here—only reference existing ones.
- Prefer consistent HTTP codes defined in
makeError.