Popsicle Status is a middleware for the `popsicle` HTTP client library, designed to automatically reject HTTP responses with undesirable status codes. It provides a simple function, `status(min?: number, max?: number)`, which returns a middleware that validates a response's status code against a specified inclusive `min` and exclusive `max` range. By default, it rejects any status outside the 200-399 range (i.e., anything not a 2xx or 3xx success/redirection code). The current stable version is `3.0.0`. This library is actively maintained, with releases primarily aligning with major updates to its peer dependencies, `popsicle` and `servie`, to ensure compatibility. Its key differentiator is its seamless integration into the `popsicle` middleware chain, simplifying error handling by transforming invalid HTTP responses into thrown errors, making control flow clearer than manual status checks.
npm install popsicle-statusVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to apply the `status` middleware to a `popsicle` request, configuring it to only allow 2xx responses, and handling both successful and rejected outcomes.
Update the `servie` peer dependency to `^4.0.0`. If unable to update, remain on `popsicle-status@2.x`.
Ensure `popsicle` is updated to version `6.x` or newer. If stuck on an older `popsicle` version, use `popsicle-status@1.x`.
Refactor error handling code to use `try/catch` blocks around calls that use `popsicle-status` middleware, as it will now throw an `Error` directly instead of returning a rejected promise.
When catching errors from `popsicle-status`, you can now safely access `err.res` for the full response object if you need to inspect headers or other response details.
Update `popsicle` to `^6.0.0` or downgrade `popsicle-status` to `1.x` to match your `popsicle` version.
Install or update `servie` to a compatible version: `npm install servie@^4.0.0` or `yarn add servie@^4.0.0`.
Wrap your `popsicle` requests using `popsicle-status` middleware in `try/catch` blocks to explicitly handle the thrown `HttpError`.