---
title: "@vltpkg/registry-client: registry-error — vlt docs"
description: "Documentation for the vlt client and the vlt registry."
url: "https://docs.vlt.io/client/api-reference/registry-client/registry-error"
image: "https://docs.vlt.io/og/client/api-reference/registry-client/registry-error"
lang: "en"
---

# registry-error

## Type Aliases

### AssertOkOptions

```ts
type AssertOkOptions = object;
```

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

#### 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

```ts
type ErrorResponse = object;
```

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

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

```ts
[k: string | number | symbol]: any
```

| Name         | Type           |
| ------------ | -------------- |
| `statusCode` | `number`       |
| `text`?      | () => `string` |

---

### RequestErrorOptions

```ts
type RequestErrorOptions = AssertOkOptions;
```

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

## Functions

### assertOk()

```ts
function assertOk(response, options): void
```

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

#### Parameters

| Parameter  | Type                                                                                                            |
| ---------- | --------------------------------------------------------------------------------------------------------------- |
| `response` | [`ErrorResponse`](https://docs.vlt.io/client/api-reference/registry-client/registry-error.md#errorresponse)     |
| `options`  | [`AssertOkOptions`](https://docs.vlt.io/client/api-reference/registry-client/registry-error.md#assertokoptions) |

#### Returns

`void`

---

### registryErrorMessage()

```ts
function registryErrorMessage(response): string
```

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

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`](https://docs.vlt.io/client/api-reference/registry-client/registry-error.md#errorresponse) |

#### Returns

`string`

---

### requestError()

```ts
function requestError(err, __namedParameters): Error
```

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

Wrap an error thrown _by_ `RegistryClient.request()` -- as opposed to a non-2xx response it returned, which is [assertOk](https://docs.vlt.io/client/api-reference/registry-client/registry-error.md#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`](https://docs.vlt.io/client/api-reference/registry-client/registry-error.md#assertokoptions) |

#### Returns

`Error`

---

### statusText()

```ts
function statusText(code): undefined | string
```

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

#### Parameters

| Parameter | Type     |
| --------- | -------- |
| `code`    | `number` |

#### Returns

`undefined` | `string`

---

### tokenRefusal()

```ts
function tokenRefusal(response): undefined | "expired" | "revoked"
```

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

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

#### Parameters

| Parameter  | Type      |
| ---------- | --------- |
| `response` | `unknown` |

#### Returns

`undefined` | `"expired"` | `"revoked"`

---

### tokenRefusalAdvice()

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

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

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`
