npm Registry API Client
    Preparing search index...

    Class NpmApiError

    Thrown when the npm Registry API returns a non-2xx response.

    import { NpmApiError } from 'npmjs-api-client';

    try {
    await npm.search({ text: 'a' });
    } catch (err) {
    if (err instanceof NpmApiError) {
    console.log(err.status); // 400
    console.log(err.statusText); // often '' (not sent by the server)
    console.log(err.detail); // "The 'text' parameter must be between 2 and 64 characters"
    console.log(err.body); // { error: "The 'text' parameter ...", code: 'ERR_TEXT_LENGTH' }
    }
    }

    Hierarchy

    • Error
      • NpmApiError
    Index

    Constructors

    Properties

    body?: unknown

    Response body: parsed JSON when the body is JSON, otherwise the raw text. undefined when the response had no body or it could not be read.

    cause?: unknown
    detail?: string

    Human-readable reason extracted from the response body, such as 'scoped packages are not currently supported in bulk lookups'.

    message: string
    name: string
    stack?: string
    status: number

    HTTP status code (e.g. 404, 401, 403)

    statusText: string

    HTTP status text (e.g. 'Not Found'). Often empty: many servers, and HTTP/2, do not send one — prefer NpmApiError.status and NpmApiError.detail.