PassageError Class

Understand the errors thrown by Passage.js

Definition

Passage.js provides a custom error class that is used to manage all errors in the library. The PassageError class consists of the following attributes.

AttributeDescription

statusCode: number

The HTTP status code returned from the API

statusText: string

Text representation of the status code (e.g. "Bad Request")

message: string

Informative message describing the specific error that occurred.

Catching Passage Errors

Import the PassageError class from @passageidentity/passage-js package.

import { Passage, PassageError } from '@passageidentity/passage-js'

Then you can catch errors in your frontend application like this.

try {
  // try to activate a magic link
  const res = await this.passage.magicLinkActivate(magicLinkValue)
} catch (err: PassageError) {
  // this method may throw an error of "Not Found" if the magic link
  // is invalid or expired
  console.log(err.message)
}

Last updated