with one click
getting-started
Define custom API errors. Use when throwing errors in an api.
Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
Menu
Define custom API errors. Use when throwing errors in an api.
Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
Based on SOC occupation classification
Use when creating or updating api specific packages in `packages/api/*`, especially for package structure, exports, module wiring, docs, and validation.
Use when implementing or reviewing HTTP integrations inside api specific packages, especially for transport choice, timeout placement, request shaping, and error handling.
Use when configuring a shared OSRM client in NestJS APIs.
Use when configuring transactional mail delivery in NestJS APIs with @wisemen/nestjs-mail.
Use when generating CSVs in APIs.
Use when scanning NestJS providers with DiscoveryService-backed utilities.
| name | getting-started |
| description | Define custom API errors. Use when throwing errors in an api. |
import { NotFoundApiError, ApiErrorCode } from "@wisemen/api-error"
export class UserNotFoundError extends NotFoundApiError {
@ApiErrorCode("user_not_found")
readonly code = "user_not_found"
constructor() {
super("The requested user was not found")
}
}
import { ApiErrorResponse } from "@wisemen/api-error"
...
export class ViewUserDetailController {
...
@ApiErrorResponse(UserNotFoundError)
async findOne(...): Promise<UserDto> {
...
}
}
it("returns 404 for unknown user", async () => {
const response = await request(...).get(...)
expect(response).toHaveApiError(new UserNotFoundError())
})
import { BadRequestApiError, ApiErrorCode, ApiErrorMeta, } from "@wisemen/api-error"
export class InvalidEmailApiErrorMeta {
@ApiProperty({ type: 'string' })
field: string
constructor(field: string) {
this.field = field
}
}
export class InvalidEmailError extends BadRequestApiError {
@ApiErrorCode("invalid_email")
readonly code = "invalid_email"
@ApiErrorMeta()
readonly meta: InvalidEmailApiErrorMeta
constructor(field: string) {
super("The email address is invalid")
this.meta = new InvalidEmailApiErrorMeta(field)
}
}