79697813

Date: 2025-07-11 04:09:47
Score: 4.5
Natty:
Report link

Not an answer to your question but I am unable to comment yet. Just thought I'd chime in and say you can clean this up a bit by putting those examples directly on ErrorBody type.

type ErrorBody = {
    /**
    * @example "https://someurl.com"
    **/
    type: string,
    /**
    * @example 409
    **/
    status: 400 | 401 | ...,
    /**
    * @example "error/409-error-one-hundred-and-fifty"
    **/
    code: string,
    /**
    * @example "This is an example of another error"
    **/
    title: string,
    /**
    * @example "You should provide error detail for all errors"
    **/
    detail: string
}

Then your endpoints can become:

@Response<ErrorBody>('409', 'A 409 error')
@Response<ErrorBody>('4XX', 'A 4xx error called fred')

I am also looking for an answer to this problem. I want all my API error responses to conform to the application/problem+json type response that can be found in this spec. I don't want to manually write out every possible @Response decorator though. I wish you could do something like:

@Response<ErrorBody>( ErrorStatusCodeEnum, 'An error' );

Where ErrorBody would now have the form

type ErrorBody = {
    /**
    * @example "https://someurl.com"
    **/
    type: string,
    /**
    * @example 409
    **/
    status: ErrorStatusCodeEnum,
    /**
    * @example "error/409-error-one-hundred-and-fifty"
    **/
    code: string,
    /**
    * @example "This is an example of another error"
    **/
    title: string,
    /**
    * @example "You should provide error detail for all errors"
    **/
    detail: string
}

and TSOA would map that to all possible error codes in the enum.

Reasons:
  • Blacklisted phrase (1): Not an answer
  • Blacklisted phrase (1): to comment
  • Blacklisted phrase (2): I am also looking
  • RegEx Blacklisted phrase (1): I want
  • Long answer (-1):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Ra.jar