npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@inrupt/solid-client-errors

v0.0.2

Published

An RFC9457 Problem Details handling library.

Downloads

12,489

Readme

Solid JavaScript Error - solid-client-errors

Contributor
Covenant

This project adheres to the Contributor Covenant code of conduct. By participating, you are expected to uphold this code. Please report unacceptable behavior to [email protected].

@inrupt/solid-client-errors is a JavaScript library for handling RFC9457 Problem Details on HTTP error responses.

Server support

This feature is currently available in ESS. Servers implementing RFC9457 Problem Details will be supported too.

Supported environments

Our JavaScript Client Libraries use relatively modern JavaScript, aligned with the ES2020 Specification features, we ship both ESM and CommonJS, with type definitions for TypeScript alongside.

This means that out of the box, we only support environments (browsers or runtimes) that were released after mid-2020, if you wish to target other (older) environments, then you will need to cross-compile our SDKs via the use of Babel, webpack, SWC, or similar.

If you need support for Internet Explorer, it is recommended to pass them through a tool like Babel, and to add polyfills for e.g. Map, Set, Promise, Headers, Array.prototype.includes, Object.entries and String.prototype.endsWith.

Node.js Support

See Inrupt Solid Javascript Client Libraries.

Installation

For the latest stable version of solid-client-errors:

npm install @inrupt/solid-client-errors

Issues & Help

Solid Community Forum

If you have questions about working with Solid or just want to share what you’re working on, visit the Solid forum. The Solid forum is a good place to meet the rest of the community.

Bugs and Feature Requests

  • For public feedback, bug reports, and feature requests please file an issue via GitHub.
  • For non-public feedback or support inquiries please use the Inrupt Service Desk.

Examples

Integrators of this library will generally use the following pattern to throw a subclass of ClientHttpError, corresponding to the response status.

import { handleErrorResponse } from "@inrupt/solid-client-errors";

const response = await fetch(url, options);

if (response.status !== 200) {
  const responseBody = await response.text();
  throw handleErrorResponse(
    response,
    responseBody,
    "application error message",
  );
}

The specific error type corresponds to the HTTP status code in the response, each of which implements the WithProblemDetails type.

  • 400: BadRequestError
  • 401: UnauthorizedError
  • 403: ForbiddenError
  • 404: NotFoundError
  • 405: MethodNotAllowedError
  • 406: NotAcceptableError
  • 409: ConflictError
  • 410: GoneError
  • 412: PreconditionFailedError
  • 415: UnsupportedMediaTypeError
  • 429: TooManyRequestsError
  • 500: InternalServerError

Each error includes a problemDetails field with the following properties:

  • type: URL: The specific error type. By default, this is about:blank.
  • title: string: A short description of the problem.
  • status: number: The error response status code.
  • detail?: string: A longer description of the problem.
  • instance?: URL: A unique URL identifying the problem occurrence.

Consumers of these errors may handle the ProblemDetails data in the following way:

const res = await getFile(url, options)
  .then((file) => { /* Do something after a successful request */ }
  .catch((err) => {
    if (hasProblemDetails(err)) {
      const problems = err.problemDetails;
      /* Do something with the details of the failed request */
    } else {
      /* Do something with a generic error message */
    }
  });

Documentation

Changelog

See the release notes.