Skip to content
API Referenceregistry-clientregistry-error

@vltpkg/registry-client/registry-error

Type Aliases

AssertOkOptions

type AssertOkOptions = object

Defined in: src/registry-client/src/registry-error.ts:87

Type declaration

advice()?
optional advice: (statusCode) => string | (string | undefined)[] | undefined;

Status-specific guidance appended to the message, one ⚠️ line per entry. Only consulted when the response is an error.

Parameters
statusCode

number

Returns

string | (string | undefined)[] | undefined

message
message: string

what we were trying to do, eg 'Failed to list dist-tags'

method?
optional method: string;

the method used; defaults to GET

url
url: URL | string

the url that was requested


ErrorResponse

type ErrorResponse = object

Defined in: src/registry-client/src/registry-error.ts:13

The parts of a CacheEntry these helpers need.

Deliberately narrow and structural rather than CacheEntry itself: RegistryClient.prototype.request is duck-typed in a dozen tests, and a helper that every command calls must not be the thing that makes those mocks illegal. text is optional for the same reason.

Type declaration

Index Signature

[k: string | number | symbol]: any
statusCode
statusCode: number
text()?
optional text: () => string;
Returns

string


RequestErrorOptions

type RequestErrorOptions = AssertOkOptions

Defined in: src/registry-client/src/registry-error.ts:158

Functions

assertOk()

function assertOk(response, options): void

Defined in: src/registry-client/src/registry-error.ts:143

Parameters

response

ErrorResponse

options

AssertOkOptions

Returns

void


registryErrorMessage()

function registryErrorMessage(response): string

Defined in: src/registry-client/src/registry-error.ts:67

Format a non-2xx registry response as "403 Forbidden — <detail>", where the detail is whatever the registry actually said.

Falls back to the bare status when the body is empty or cannot be decoded, and to the raw body text when it is not JSON.

Parameters

response

ErrorResponse

Returns

string


requestError()

function requestError(err, __namedParameters): Error

Defined in: src/registry-client/src/registry-error.ts:184

Wrap an error thrown by RegistryClient.request() — as opposed to a non-2xx response it returned, which is assertOk’s job.

A command that catches such an error and rethrows a flat error(message, { code: 'EREQUEST' }) throws away the only part the user needed: an expired token arrives here as “Missing or invalid authentication token…”, and the rethrow reduces that to “Failed to publish package” with the real reason buried in an error log.

The auth challenges in otplease throw rather than return, but they still carry the response that provoked them. Where there is a status to be had, this builds the error through the same path a returned response takes, so a thrown 401 and a refused 401 read identically. The thrown message is the reason and is never dropped: it is the detail after the status, unless the registry’s own words are readable, in which case those are the detail and the reason becomes a ⚠️ line ahead of whatever advice the caller adds.

With no status at all — a genuine transport failure — the inner cause’s message is appended so a redirect loop or a refused socket names itself, and that cause is carried through for printErr to show as Code/Syscall.

Parameters

err

unknown

__namedParameters

AssertOkOptions

Returns

Error