Error categories and propagation
Errors describe failed operations. A service should distinguish expected failures, such as a missing record, from unexpected faults that may compromise its state. This is an application design distinction, not a built-in Node error classification. Use Error with a cause to preserve the original failure when adding context. Prefer stable documented error codes over matching human-readable messages. Promise failures propagate through await, whereas an EventEmitter error requires an appropriate listener or is thrown. Translate known domain errors to safe public responses at the boundary. Unknown faults must be observed and handled according to the integrity of the process; an uncaughtException handler is not a license to keep serving after corruption. Do not return a stack trace or raw underlying error to clients. Avoid swallowing unexpected faults by treating every exception as a 400 response. Sources: https://nodejs.org/download/release/v22.16.0/docs/api/errors.html.
Formal Syntax & Structure
new Error(message, {cause}); error.codeWorking Example
const original=Object.assign(new Error('synthetic read failed'),{code:'EIO'});try {try{throw original;}catch(cause){throw new Error('Catalog unavailable',{cause});}}catch(error){console.log(error.message);console.log(error.cause.code);console.log(error.cause===original);}