Briefle words · Code & architecture
instanceof check
Asking whether a value is of a given type, which is how code catches one specific kind of error and not another.
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's httpStatus uses 'e instanceof NotFoundError ? 404'. B uses 'String(e).includes("not found")', which breaks as soon as the wording changes.
Related words
Room 4 · Errors & edge cases
Learn “instanceof check” in a five-minute lesson