Skip to content

PostcodeError

The error that each call of PostcodeClient raises when it cannot give a result. A cancelled call raises the platform’s own abort error instead.

import { PostcodeClient, PostcodeError } from '@gatepost/client';
const client = new PostcodeClient({ apiKey: process.env['NIPOST_API_KEY'] });
try {
await client.lookup('FC-01-Z99');
} catch (error) {
if (error instanceof PostcodeError) {
error.code; // 'invalid_input'
error.status; // null
}
}
  • Error

new PostcodeError(code, message, details?): PostcodeError

Makes an error. The client makes each one. A test of code that uses the client can make one too.

PostcodeErrorCode

Why the call failed.

string

What happened and what to do, with no API key in it.

Readonly<{ apiCode?: string | null; cause?: unknown; retryAfterMs?: number | null; status?: number | null; }> = {}

The status, the apiCode, the retryAfterMs and the cause. Each one that is missing is null.

PostcodeError

Error.constructor

readonly apiCode: string | null

The error.code of the response body, or null.


readonly code: PostcodeErrorCode

Why the call failed, as a stable code.


readonly name: string = 'PostcodeError'

Always PostcodeError, so that a log names the error type.

Error.name


readonly retryAfterMs: number | null

The wait that Retry-After asked for, in milliseconds, or null.


readonly status: number | null

The HTTP status of the response, or null when no response arrived.

Unofficial. Not made or endorsed by NIPOST.