Briefle words · Code & architecture
Custom error class
Your own named kind of error, built on the language's Error type, so code can tell different failures apart.
Say it to an AI
TypeScript getEpisode(id) service. Define custom error classes NotFoundError and ValidationError extending Error, throw them instead of strings or generic Errors, and map them to 404/400 in one httpStatus helper with instanceof checks, falling back to 500.
How an expert would brief the stronger version of “Episode lookup errors”.
See it
Try it as a puzzle →Service function behind GET /episodes/:id in a podcast app, plus the helper that maps its errors to HTTP status codes.
Why: A declares 'class NotFoundError extends Error {}' and 'class ValidationError extends Error {}'. B throws a plain 'new Error(...)' for both.
Related words
Room 4 · Errors & edge cases
Learn “Custom error class” in a five-minute lesson