vlt / docs

  • PricingBenchmarks (opens in new window)Community (opens in new window)Feedback
  • Overview
    • Overview
    • cache-entry
    • index
    • Reference
    • registry-error
    • store-root
  • Type Aliases
  • AssertOkOptions
  • ErrorResponse
  • RequestErrorOptions
  • Functions
  • assertOk()
  • registryErrorMessage()
  • requestError()
  • tokenRefusal()
  • tokenRefusalAdvice()
  1. Client
  2. /
  3. API Reference
  4. /
  5. @vltpkg/registry-client
  6. /
  7. registry-error

registry-error

Type Aliases

AssertOkOptions

TypeScript
type AssertOkOptions = object;

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

Type declaration

NameTypeDescription
advice?(statusCode) => string | (string | undefined)[] | undefinedStatus-specific guidance appended to the message, one ⚠️ line per entry. Only consulted when the response is an error.
messagestringwhat we were trying to do, eg 'Failed to list dist-tags'
method?stringthe method used; defaults to GET
urlURL | stringthe url that was requested

ErrorResponse

TypeScript
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

TypeScript
[k: string | number | symbol]: any
NameType
statusCodenumber
text?() => string

RequestErrorOptions

TypeScript
type RequestErrorOptions = AssertOkOptions;

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

Functions

assertOk()

TypeScript
function assertOk(response, options): void

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

Parameters

ParameterType
responseErrorResponse
optionsAssertOkOptions

Returns

void


registryErrorMessage()

TypeScript
function registryErrorMessage(response): string

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

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

ParameterType
responseErrorResponse

Returns

string


requestError()

TypeScript
function requestError(err, __namedParameters): Error

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

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

ParameterType
errunknown
__namedParametersAssertOkOptions

Returns

Error


tokenRefusal()

TypeScript
function tokenRefusal(response): undefined | "expired" | "revoked"

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

How a 401 says the token it refused died, if it does.

Parameters

ParameterType
responseunknown

Returns

undefined | "expired" | "revoked"


tokenRefusalAdvice()

TypeScript
function tokenRefusalAdvice(response, url?): undefined | string

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

What to do about a 401 that says the token expired or was revoked, or undefined for every other response. The account is the first path segment of any request to a vlt registry, and one token covers every registry on it.

Parameters

ParameterType
responseunknown
url?string | URL

Returns

undefined | string


PreviousReferenceNextstore-root

On this page

  • Type Aliases
  • AssertOkOptions
  • ErrorResponse
  • RequestErrorOptions
  • Functions
  • assertOk()
  • registryErrorMessage()
  • requestError()
  • tokenRefusal()
  • tokenRefusalAdvice()

Deploy your package on vlt.io

Publish scoped and private packages, manage organizations and access, and give every developer and CI environment a consistent source for public and private JavaScript dependencies.

Publish now