The SDK is currently in active development. For more details, see the U301 Postman docs.

Error handling

Robust error handling for u301: error codes, classes, HTTP status mapping, TypeScript-safe detection with isU301Error, usage examples and best practices.

Error Codes

Error CodeError ClassHttp Status CodeDescription
BAD_REQUESTBadRequestError400The request was invalid or cannot be processed.
UNAUTHORIZEDUnauthorizedError401Authentication is required and has failed or has not been provided.
FORBIDDENForbiddenError403The request is valid but the server is refusing action.
NOT_FOUNDNotFoundError404The requested resource could not be found.
VALIDATION_FAILEDValidationError422The request was well-formed but contained invalid data.
RATE_LIMITEDRateLimitError429Too many requests have been made in a given amount of time.
NETWORK_ERRORNetworkError0No HTTP response status code was received or could be reported for a network request
SERVER_ERRORServerError>= 500The server encountered an error while processing the request.
UNKNOWNOtherAn unknown error occurred.

When a matching Error Code is encountered, the u301 library throws the corresponding error class. Use isU301Error to determine whether an error originated from the u301 library. Supplying an Error Code also narrows the TypeScript type.

import { isU301Error, U301 } from 'u301'
try {
    const u301 = new U301({
        apiKey: '<YOUR_API_KEY>',
        workspaceId: '<YOUR_WORKSPACE_ID>',
        debug: true,
    })
    await u301.links.create('https://example.com')
} catch (error) {
    if (isU301Error(error, 'RATE_LIMITED')) { // [!code highlight]
        console.log('Rate limited, please try again later')
    }
}

Last updated on

On this page