ForestAdmin/lumber

View on GitHub
services/oidc/error.js

Summary

Maintainability
A
0 mins
Test Coverage
B
88%
const openIdClient = require('openid-client');
const LumberError = require('../../utils/lumber-error');

class OidcError extends LumberError {
  /**
   * @param {string} message
   * @param {Error|undefined} origin
   * @param {string} [possibleSolution]
   */
  constructor(message, origin, possibleSolution) {
    let reason;

    if (origin instanceof openIdClient.errors.OPError) {
      /** @public @readonly @type {string} */
      reason = origin.error || origin.message;
    } else if (origin) {
      reason = origin.message;
    }

    super(message, undefined, { reason, possibleSolution });

    this.name = 'OidcError';
  }
}

module.exports = OidcError;