Source

lib/is-jwt-validator-error.js

'use strict'

const { BaseError } = require('./errors')

/**
 * @description Checks if the given error was generated by the JWT Validator.
 * @param {Error} err - An instance of an error.
 * @returns {boolean} Returns true if the error was generated by the JWT Validator.
 * Otherwise returns false.
 *
 * @example
 *
 * 'use strict';
 *
 * const { JWTValidator, isJWTValidatorError } = require('aws-cognito-express');
 *
 * const jwtValidator = new JWTValidator({ ... });
 * const token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
 *
 * const err = new Error('Unexpected error');
 * isJWTValidatorError(err);
 * // => false
 *
 * jwtValidator.validate(token)
 *  .catch((err) => {
 *    isJWTValidatorError(err);
 *    // => true
 *  });
 * */
function isJWTValidatorError(err) {
  return err instanceof BaseError && err.isJWTValidatorError === true
}

module.exports = isJWTValidatorError