You are here

public static function JwtDecodeException::newFromException in JSON Web Token Authentication (JWT) 8

Same name and namespace in other branches
  1. 8.0 src/Transcoder/JwtDecodeException.php \Drupal\jwt\Transcoder\JwtDecodeException::newFromException()

Construct a new decode exception from a php-jwt exception.

Parameters

\Exception $e: The exception to decode.

Return value

JwtDecodeException The decode exception.

1 call to JwtDecodeException::newFromException()
JwtTranscoder::decode in src/Transcoder/JwtTranscoder.php
Gets a validated JsonWebToken from an encoded JWT.

File

src/Transcoder/JwtDecodeException.php, line 32

Class

JwtDecodeException
Class JwtDecodeException.

Namespace

Drupal\jwt\Transcoder

Code

public static function newFromException(\Exception $e) {
  switch ($e) {
    case $e instanceof SignatureInvalidException:
      return new static($e
        ->getMessage(), self::SIGNATURE_INVALID, $e);
    case $e instanceof BeforeValidException:
      return new static($e
        ->getMessage(), self::BEFORE_VALID, $e);
    case $e instanceof ExpiredException:
      return new static($e
        ->getMessage(), self::EXPIRED, $e);
    case $e instanceof \Exception:
      return new static('Internal Server Error', self::UNKNOWN, $e);
    default:
      return new static('Internal Server Error', self::UNKNOWN, $e);
  }
}