{"library":"standard-http-error","title":"Standard HTTP Error Class","type":"library","description":"The `standard-http-error` package provides a minimalist, extensible JavaScript error class (`HttpError`) specifically designed for representing HTTP status codes. It allows for easy detection of HTTP-related errors using `instanceof` checks within error handling middleware. Currently at version 2.0.1, the core library has not seen updates since 2017, suggesting it is effectively abandoned by its original author, though type definitions are community-maintained. It follows semantic versioning for its major versions. Its key differentiators include its small footprint, direct alignment with standard HTTP status codes (supporting both numeric codes and descriptive names like \"NOT_FOUND\"), and features for proper error serialization. It offers compatibility with frameworks like Express and Koa by providing non-enumerable aliases for `code` and `message` as `status`, `statusCode`, and `statusMessage` for consistent error object structures.","language":"javascript","status":"abandoned","last_verified":"Tue Apr 21","install":{"commands":["npm install standard-http-error"],"cli":null},"imports":["import HttpError from 'standard-http-error';","const HttpError = require('standard-http-error');","if (err.code === HttpError.NOT_FOUND) { /* ... */ }"],"auth":{"required":false,"env_vars":[]},"links":{"homepage":null,"github":"https://github.com/moll/js-standard-http-error","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/standard-http-error","openapi_spec":null,"status_page":null,"smithery":null},"quickstart":{"code":"import HttpError from 'standard-http-error';\n\ntry {\n  // Create an HTTP error with a specific code\n  throw new HttpError(404);\n} catch (err) {\n  if (err instanceof HttpError) {\n    console.log(`Caught HttpError: ${err.name} (${err.code}) - ${err.message}`); // Output: HttpError (404) - Not Found\n  }\n}\n\ntry {\n  // Create an HTTP error with a named code and custom message\n  throw new HttpError(HttpError.FORBIDDEN, 'Access to this resource is denied');\n} catch (err) {\n  if (err instanceof HttpError) {\n    console.log(`Caught HttpError: ${err.name} (${err.code}) - ${err.message}`); // Output: HttpError (403) - Access to this resource is denied\n  }\n}\n\ntry {\n  // Create an HTTP error with custom properties\n  throw new HttpError(412, 'Bad CSRF Token', { url: '/api/resource', userId: 'user123' });\n} catch (err) {\n  if (err instanceof HttpError) {\n    console.log(`Caught HttpError with custom props: ${err.code} - ${err.message}. URL: ${err.url}, User: ${err.userId}`);\n  }\n}","lang":"typescript","description":"Demonstrates creating `HttpError` instances with numeric codes, named codes, custom messages, and custom properties, and catching them with `instanceof`.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}