registry-error
Type Aliases
AssertOkOptions
type AssertOkOptions = object;Defined in: src/registry-client/src/registry-error.ts:149
Type declaration
| Name | Type | Description |
|---|---|---|
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. |
message | string | what we were trying to do, eg 'Failed to list dist-tags' |
method? | string | the method used; defaults to GET |
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| Name | Type |
|---|---|
statusCode | number |
text? | () => string |
RequestErrorOptions
type RequestErrorOptions = AssertOkOptions;Defined in: src/registry-client/src/registry-error.ts:222
Functions
assertOk()
function assertOk(response, options): voidDefined in: src/registry-client/src/registry-error.ts:207
Parameters
| Parameter | Type |
|---|---|
response | ErrorResponse |
options | AssertOkOptions |
Returns
void
registryErrorMessage()
function registryErrorMessage(response): stringDefined 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
| Parameter | Type |
|---|---|
response | ErrorResponse |
Returns
string
requestError()
function requestError(err, __namedParameters): ErrorDefined 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
| Parameter | Type |
|---|---|
err | unknown |
__namedParameters | AssertOkOptions |
Returns
Error
tokenRefusal()
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
| Parameter | Type |
|---|---|
response | unknown |
Returns
undefined | "expired" | "revoked"
tokenRefusalAdvice()
function tokenRefusalAdvice(response, url?): undefined | stringDefined 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
| Parameter | Type |
|---|---|
response | unknown |
url? | string | URL |
Returns
undefined | string