Construct an ApiException with a useful message, including decoded metadata.

@param string $basicMessage
@param int $rpcCode
@param mixed[]|RepeatedField $metadata
@param array $decodedMetadata
@param \Exception|null $previous
@return ApiException
180509
private static function create($basicMessage, $rpcCode, $metadata, array $decodedMetadata, $previous = null)
    {
        $rpcStatus = ApiStatus::statusFromRpcCode($rpcCode);
        $messageData = [
            'message' => $basicMessage,
            'code' => $rpcCode,
            'status' => $rpcStatus,
            'details' => $decodedMetadata
        ];

        $message = json_encode($messageData, JSON_PRETTY_PRINT);

        return new ApiException($message, $rpcCode, $rpcStatus, [
            'previous' => $previous,
            'metadata' => $metadata,
            'basicMessage' => $basicMessage,
        ]);
    }
974972
public static function makeFromException($e, $overrideCode = null)
    {
        $code = $overrideCode === null ? $e->getCode() : $overrideCode;

        if ($e instanceof static) {
            $e->code = $code;

            return $e;
        }

        return new static($e->getMessage(), $code, $e);
    }
1056481
public MAPErrorMessage createMessageFromErrorCode(Long errorCode) {
        long ec = (long) errorCode;
        switch ((int) ec) {
            case MAPErrorCode.unexpectedDataValue:
            case MAPErrorCode.dataMissing:
            case MAPErrorCode.unidentifiedSubscriber:
            case MAPErrorCode.illegalSubscriber:
            case MAPErrorCode.illegalEquipment:
            case MAPErrorCode.teleserviceNotProvisioned:
            case MAPErrorCode.messageWaitingListFull:
            case MAPErrorCode.unauthorizedRequestingNetwork:
            case MAPErrorCode.resourceLimitation:
            case MAPErrorCode.unknownOrUnreachableLCSClient:
            case MAPErrorCode.incompatibleTerminal:
            case MAPErrorCode.noRoamingNumberAvailable:
            case MAPErrorCode.noSubscriberReply:
            case MAPErrorCode.forwardingFailed:
            case MAPErrorCode.orNotAllowed:
            case MAPErrorCode.forwardingViolation:
            case MAPErrorCode.numberChanged:
            case MAPErrorCode.unknownMSC:
            case MAPErrorCode.unknownEquipment:
            case MAPErrorCode.bearerServiceNotProvisioned:
            case MAPErrorCode.mmEventNotSupported:
            case MAPErrorCode.illegalSSOperation:
            case MAPErrorCode.ssNotAvailable:
            case MAPErrorCode.ssSubscriptionViolation:
            case MAPErrorCode.unknownAlphabet:
            case MAPErrorCode.ussdBusy:
            case MAPErrorCode.negativePWCheck:
            case MAPErrorCode.numberOfPWAttemptsViolation:
            case MAPErrorCode.shortTermDenial:
            case MAPErrorCode.longTermDenial:
                return new MAPErrorMessageExtensionContainerImpl(errorCode);

            case MAPErrorCode.smDeliveryFailure:
                return new MAPErrorMessageSMDeliveryFailureImpl();

            case MAPErrorCode.absentSubscriberSM:
                return new MAPErrorMessageAbsentSubscriberSMImpl();

            case MAPErrorCode.systemFailure:
                return new MAPErrorMessageSystemFailureImpl();

            case MAPErrorCode.callBarred:
                return new MAPErrorMessageCallBarredImpl();

            case MAPErrorCode.facilityNotSupported:
                return new MAPErrorMessageFacilityNotSupImpl();

            case MAPErrorCode.unknownSubscriber:
                return new MAPErrorMessageUnknownSubscriberImpl();

            case MAPErrorCode.subscriberBusyForMTSMS:
                return new MAPErrorMessageSubscriberBusyForMtSmsImpl();

            case MAPErrorCode.absentSubscriber:
                return new MAPErrorMessageAbsentSubscriberImpl();

            case MAPErrorCode.unauthorizedLCSClient:
                return new MAPErrorMessageUnauthorizedLCSClientImpl();

            case MAPErrorCode.positionMethodFailure:
                return new MAPErrorMessagePositionMethodFailureImpl();

            case MAPErrorCode.busySubscriber:
                return new MAPErrorMessageBusySubscriberImpl();

            case MAPErrorCode.cugReject:
                return new MAPErrorMessageCUGRejectImpl();

            case MAPErrorCode.roamingNotAllowed:
                return new MAPErrorMessageRoamingNotAllowedImpl();

            case MAPErrorCode.ssErrorStatus:
                return new MAPErrorMessageSsErrorStatusImpl();

            case MAPErrorCode.ssIncompatibility:
                return new MAPErrorMessageSsIncompatibilityImpl();

            case MAPErrorCode.pwRegistrationFailure:
                return new MAPErrorMessagePwRegistrationFailureImpl();

            default:
                return new MAPErrorMessageParameterlessImpl(errorCode);
        }

    }
1326867
public static function createExceptionForResponse(
        array $allMessage,
        int $responseCode,
        string $responseId
    ): ApiException {
        $errorMessage = static::generateErrorMessage($responseCode, $allMessage, $responseId);

        switch ($responseCode) {
            case self::HTTP_RESPONSE_CODE_BAD_REQUEST:
                return new BadRequestException($errorMessage, $responseCode, $responseId);
            case self::HTTP_RESPONSE_CODE_UNAUTHORIZED:
                return new UnauthorizedException($errorMessage, $responseCode, $responseId);
            case self::HTTP_RESPONSE_CODE_FORBIDDEN:
                return new ForbiddenException($errorMessage, $responseCode, $responseId);
            case self::HTTP_RESPONSE_CODE_NOT_FOUND:
                return new NotFoundException($errorMessage, $responseCode, $responseId);
            case self::HTTP_RESPONSE_CODE_METHOD_NOT_ALLOWED:
                return new MethodNotAllowedException($errorMessage, $responseCode, $responseId);
            case self::HTTP_RESPONSE_CODE_TOO_MANY_REQUESTS:
                return new TooManyRequestsException($errorMessage, $responseCode, $responseId);
            case self::HTTP_RESPONSE_CODE_INTERNAL_SERVER_ERROR:
                return new PleaseContactBunqException($errorMessage, $responseCode, $responseId);
            default:
                return new UnknownApiErrorException($errorMessage, $responseCode, $responseId);
        }
    }
251552
@Override
  public <T> T decode(Message message, java.lang.Class<T> yourDomainMessageObject) throws RecoderException {
    Object rc = null;
    ClassInfo c = storage.getClassInfo(yourDomainMessageObject);
    CommandDscr cd = c.getAnnotation(CommandDscr.class);
    if (cd != null) {
      try {
        if (message.getCommandCode() != cd.code()) {
          throw new IllegalArgumentException("Invalid message code " + message.getCommandCode());
        }
        if (message.getApplicationId() != 0 && message.getApplicationId() != cd.appId()) {
          throw new IllegalArgumentException("Invalid Application-Id " + message.getApplicationId());
        }
        for (CommandFlag f : cd.flags()) {
          switch (f) {
            case E:
              if (!message.isError()) {
                throw new IllegalArgumentException("Flag e is not set");
              }
              break;
            case P:
              if (!message.isProxiable()) {
                throw new IllegalArgumentException("Flag p is not set");
              }
              break;
            case R:
              if (!message.isRequest()) {
                throw new IllegalArgumentException("Flag m is not set");
              }
              break;
            case T:
              if (!message.isReTransmitted()) {
                throw new IllegalArgumentException("Flag t is not set");
              }
              break;
          }
        }
        // Find max constructor + lost avp set by setters
        int cacount = 0;
        Constructor<?> cm = null;
        Map<String, Class<?>> cmargs = new HashMap<String, Class<?>>();
        for (ConstructorInfo ci : c.getConstructorsInfo()) {
          if (ci.getAnnotation(Setter.class) != null) {
            // check params - all params must have avp annotation
            Class<?>[] params = ci.getConstructor().getParameterTypes();
            boolean correct = true;
            for (Class<?> j : params) {
              if (j.isArray()) {
                j = j.getComponentType();
              }
              if (storage.getClassInfo(j).getAnnotation(AvpDscr.class) == null) {
                correct = false;
                break;
              }
            }
            if (!correct) {
              continue;
            }
            // find max args constructor
            if (cacount < params.length) {
              cacount = params.length;
              cm = ci.getConstructor();
            }
          }
        }
        // fill cm args
        List<Object> initargs = new ArrayList<Object>();
        if (cm != null) {
          for (Class<?> ac : cm.getParameterTypes()) {
            Class<?> lac = ac.isArray() ? ac.getComponentType() : ac;
            cmargs.put(lac.getName(), ac);
            // Create params
            initargs.add(createChildByAvp(findChildDscr(cd.childs(), ac), ac, message.getAvps()));
          }
          // Create instance class
          rc = cm.newInstance(initargs.toArray());
        } else {
          rc = yourDomainMessageObject.newInstance();
        }
        //
        for (MethodInfo mi : c.getMethodsInfo()) {
          if (mi.getAnnotation(Setter.class) != null) {
            Class<?>[] pt = mi.getMethod().getParameterTypes();
            if (pt.length == 1 && storage.getClassInfo(pt[0]).getAnnotation(AvpDscr.class) != null) {
              Class<?> ptc = pt[0].isArray() ? pt[0].getComponentType() : pt[0];
              if (!cmargs.containsKey(ptc.getName())) {
                cmargs.put(ptc.getName(), ptc);
                mi.getMethod().invoke(rc, createChildByAvp(findChildDscr(cd.childs(), pt[0]), pt[0], message.getAvps()));
              }
            }
          }
        }
        // Fill undefined avp
        setUndefinedAvp(message.getAvps(), rc, c, cmargs);
      } catch (InstantiationException e) {
        throw new RecoderException(e);
      } catch (InvocationTargetException e) {
        throw new RecoderException(e);
      } catch (IllegalAccessException e) {
        throw new RecoderException(e);
      }
    }
    return (T) rc;
  }
1043543
@FFDCIgnore(IOException.class)
    public boolean processWithWholeMessageHandler(DATA_TYPE dt) throws CharacterCodingException {
        if ((appTextMessageHandler != null) && (dt == DATA_TYPE.TEXT)) {

            Class<?> clazz = appTextMessageHandlerClass;

            if (clazz.equals(String.class)) {
                String message = convertMessageToString();

                // call the application's MessageHandler.onMessage(<String> x) method
                connLink.setReadLinkStatus(READ_LINK_STATUS.ON_READ_THREAD);
                ((MessageHandler.Whole<String>) appTextMessageHandler).onMessage(message);
                return true;
            }

            else if (clazz.equals(Reader.class)) {
                Reader message = convertMessageToReader();

                // call the application's MessageHandler.onMessage(<Reader> x) method
                connLink.setReadLinkStatus(READ_LINK_STATUS.ON_READ_THREAD);
                ((MessageHandler.Whole<Reader>) appTextMessageHandler).onMessage(message);
                return true;
            }
        }

        if ((appBinaryMessageHandler != null) && (dt == DATA_TYPE.BINARY)) {
            Class<?> clazz = appBinaryMessageHandlerClass;

            if (clazz.equals(ByteBuffer.class)) {
                ByteBuffer message = convertMessageToByteBuffer();

                // call the application's MessageHandler.onMessage(<ByteBuffer> x) method
                connLink.setReadLinkStatus(READ_LINK_STATUS.ON_READ_THREAD);
                ((MessageHandler.Whole<ByteBuffer>) appBinaryMessageHandler).onMessage(message);
                return true;
            }

            else if (clazz.equals(byte[].class)) {
                byte[] message = convertPayloadToByteArray();

                // call the application's MessageHandler.onMessage(<byte[]> x) method
                connLink.setReadLinkStatus(READ_LINK_STATUS.ON_READ_THREAD);
                ((MessageHandler.Whole<byte[]>) appBinaryMessageHandler).onMessage(message);
                return true;
            }

            else if (clazz.equals(InputStream.class)) {
                InputStream message = convertMessageToInputStream();

                // call the application's MessageHandler.onMessage(<InputStream> x) method
                connLink.setReadLinkStatus(READ_LINK_STATUS.ON_READ_THREAD);
                ((MessageHandler.Whole<InputStream>) appBinaryMessageHandler).onMessage(message);
                return true;
            }
        }
        if ((appPongMessageHandler != null) && (dt == DATA_TYPE.PONG)) {
            Class<?> clazz = appPongMessageHandlerClass;
            if (clazz.equals(PongMessage.class)) {
                ByteBuffer message = convertMessageToByteBuffer(true);
                PongMessage msg = new PongMessageImpl(message);

                // call the application's MessageHandler.onMessage(<Reader> x) method
                connLink.setReadLinkStatus(READ_LINK_STATUS.ON_READ_THREAD);
                ((MessageHandler.Whole<PongMessage>) appPongMessageHandler).onMessage(msg);
                return true;
            }
        }

        // if the generic type for this MessageHandler.Whole equals one of the configured decoder generic types, then use that decoder
        // clazz: is the generic class that the MessageHandler.Whole specifies
        // then go through the decoders that also have been specified with this same (or assignable) generic class.
        // in other words, let me see if I have any decoders<X> to use with this  MessageHandler<X>.
        if ((appTextMessageHandler != null) && (dt == DATA_TYPE.TEXT)) {

            Class<?> clazz = appTextMessageHandlerClass;
            ArrayList<Decoder> dcList = findDecoderFromAppDecoderType(clazz, dt);

            if (dcList != null && dcList.size() > 0) {
                Decoder firstDecoder = dcList.get(0);
                if (firstDecoder instanceof Decoder.Text) {
                    String message = convertMessageToString();
                    //user might have declared multiple decoders of same type for this endpoint. In this case, check
                    //decoder list and find the first decoder in the list which has implemented willDecode(..) to return
                    //'true'
                    Decoder dc = findWillDecodeDecoder(dcList, message);
                    if (dc != null) {
                        try {
                            dc.init(endpointConfig);
                            Object appObj = ((Decoder.Text) dc).decode(message);
                            connLink.setReadLinkStatus(READ_LINK_STATUS.ON_READ_THREAD);
                            ((MessageHandler.Whole) appTextMessageHandler).onMessage(appObj);
                            return true;
                        } catch (DecodeException e) {
                            connLink.callOnError(e, true);
                            return true;
                        }
                    }
                } else if (firstDecoder instanceof Decoder.TextStream) {
                    Reader message = convertMessageToReader();
                    try {
                        //WebSocket API does not support willDecode() method for Decoder.BinaryStream type. Hence, even if
                        //user has declared multiple same type of decoder, just pick the first one in the list and use it.

                        firstDecoder.init(endpointConfig);
                        Object appObj = ((Decoder.TextStream) firstDecoder).decode(message);
                        connLink.setReadLinkStatus(READ_LINK_STATUS.ON_READ_THREAD);
                        ((MessageHandler.Whole) appTextMessageHandler).onMessage(appObj);
                        return true;
                    } catch (DecodeException e) {
                        connLink.callOnError(e, true);
                        return true;
                    } catch (IOException e) {
                        if (tc.isDebugEnabled()) {
                            Tr.debug(tc, "IOException calling onMessage on class " + clazz.getName() + " while decoding Decoder.TextStream type "
                                         + ((Decoder.TextStream) firstDecoder).toString()
                                         + "Exception is: " + e.getMessage());
                        }
                        //Since IOexception has occurred, there is no point in attempting to read message TextStream to convert into
                        //message string to pass as first param to form DecodeException. Hence passing just a error message
                        //"IOException decoding BinaryStream" as first parameter here
                        String msg = Tr.formatMessage(tc,
                                                      "decoder.ioexception",
                                                      appTextMessageHandler.getClass().getName(), firstDecoder.getClass().getName());

                        DecodeException de = new DecodeException(msg, e.getMessage(), e);
                        connLink.callOnError(de, true);
                        return true;
                    }
                }
            }
        }

        if ((appBinaryMessageHandler != null) && (dt == DATA_TYPE.BINARY)) {
            Class<?> clazz = appBinaryMessageHandlerClass;
            ArrayList<Decoder> dcList = findDecoderFromAppDecoderType(clazz, dt);

            if (dcList != null && dcList.size() > 0) {
                Decoder firstDecoder = dcList.get(0);
                if (firstDecoder instanceof Decoder.Binary) {
                    // Decode the given bytes into an object of type T
                    ByteBuffer message = convertMessageToByteBuffer();
                    //user might have declared multiple decoders of same type for this endpoint. In this case, check
                    //decoder list and find the first decoder in the list which has implemented willDecode(..) to return
                    //'true'
                    Decoder dc = findWillDecodeDecoder(dcList, message);
                    if (dc != null) {
                        try {
                            dc.init(endpointConfig);
                            Object appObj = ((Decoder.Binary) dc).decode(message);
                            connLink.setReadLinkStatus(READ_LINK_STATUS.ON_READ_THREAD);
                            ((MessageHandler.Whole) appBinaryMessageHandler).onMessage(appObj);
                            return true;
                        } catch (DecodeException e) {
                            connLink.callOnError(e, true);
                            return true;
                        }
                    } else {
                        if (tc.isDebugEnabled()) {
                            Tr.debug(tc, "willDecode returned false");
                        }
                        return true;
                    }
                } else if (firstDecoder instanceof Decoder.BinaryStream) {
                    InputStream message = convertMessageToInputStream();
                    try {
                        //WebSocket API does not support willDecode() method for Decoder.BinaryStream type. Hence, even if
                        //user has declared multiple same type of decoder, just pick the first one in the list and use it.
                        firstDecoder.init(endpointConfig);
                        Object appObj = ((Decoder.BinaryStream) firstDecoder).decode(message);
                        connLink.setReadLinkStatus(READ_LINK_STATUS.ON_READ_THREAD);
                        ((MessageHandler.Whole) appBinaryMessageHandler).onMessage(appObj);
                        return true;
                    } catch (DecodeException e) {
                        connLink.callOnError(e, true);
                        return true;
                    } catch (IOException e) {
                        // do NOT allow instrumented FFDC to be used here
                        if (tc.isDebugEnabled()) {
                            Tr.debug(tc, "IOException calling onMessage on class " + clazz.getName() + " while decoding Decoder.BinaryStream type "
                                         + ((Decoder.BinaryStream) firstDecoder).toString()
                                         + "Exception is: " + e.getMessage());
                        }
                        //Since IOexception has occurred, there is no point in attempting to read message BinaryStream to convert into
                        //message string to pass as first param to form DecodeException. Hence passing just a error message
                        //"IOException decoding BinaryStream" as first parameter here
                        String msg = Tr.formatMessage(tc,
                                                      "decoder.ioexception",
                                                      appBinaryMessageHandler.getClass().getName(), ((Decoder.BinaryStream) firstDecoder).getClass().getName());
                        DecodeException de = new DecodeException(msg, e.getMessage(), e);
                        connLink.callOnError(de, true);
                        return true;
                    }
                }
            }
        }
        return false;
    }
1103397
public Object decode(byte[] frame, int offset, int indirect, JMFMessageData msg) throws JMFMessageCorruptionException {
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) JmfTr.entry(this, tc, "decode", new Object[]{frame, offset, indirect, msg});
    Object result = null;
    if (indirect < 0) {
      indirect = this.indirect;
    }
    if (indirect > 0) {
      result = new JSVaryingListImpl(frame, offset, element, indirect);
    }
    else if (varying) {
      result = new JSVaryingListImpl(frame, offset, element, 0);
    }
    else {
      result = new JSFixedListImpl(frame, offset, element);
    }
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) JmfTr.exit(this, tc, "decode",  result);
    return result;
  }
620493
public GatewayMessage decode(ByteBuf byteBuf) throws MessageCodecException {
    try (InputStream stream = new ByteBufInputStream(byteBuf, true)) {
      JsonParser jp = jsonFactory.createParser(stream);
      GatewayMessage.Builder result = GatewayMessage.builder();

      JsonToken current = jp.nextToken();
      if (current != JsonToken.START_OBJECT) {
        throw new MessageCodecException("Root should be object", null);
      }
      long dataStart = 0;
      long dataEnd = 0;
      while ((jp.nextToken()) != JsonToken.END_OBJECT) {
        String fieldName = jp.getCurrentName();
        current = jp.nextToken();
        if (current == VALUE_NULL) {
          continue;
        }

        if (fieldName.equals(DATA_FIELD)) {
          dataStart = jp.getTokenLocation().getByteOffset();
          if (current.isScalarValue()) {
            if (!current.isNumeric() && !current.isBoolean()) {
              jp.getValueAsString();
            }
          } else if (current.isStructStart()) {
            jp.skipChildren();
          }
          dataEnd = jp.getCurrentLocation().getByteOffset();
        } else {
          // headers
          result.header(fieldName, jp.getValueAsString());
        }
      }
      // data
      if (dataEnd > dataStart) {
        result.data(byteBuf.copy((int) dataStart, (int) (dataEnd - dataStart)));
      }
      return result.build();
    } catch (Throwable ex) {
      throw new MessageCodecException("Failed to decode message", ex);
    }
  }
188661
private static function _specificAPIError($rbody, $rcode, $rheaders, $resp, $errorData)
    {
        $msg = isset($errorData['message']) ? $errorData['message'] : null;
        $param = isset($errorData['param']) ? $errorData['param'] : null;
        $code = isset($errorData['code']) ? $errorData['code'] : null;
        $type = isset($errorData['type']) ? $errorData['type'] : null;

        switch ($rcode) {
            case 400:
                // 'rate_limit' code is deprecated, but left here for backwards compatibility
                // for API versions earlier than 2015-09-08
                if ($code == 'rate_limit') {
                    return new Error\RateLimit($msg, $param, $rcode, $rbody, $resp, $rheaders);
                }
                if ($type == 'idempotency_error') {
                    return new Error\Idempotency($msg, $rcode, $rbody, $resp, $rheaders);
                }

                // intentional fall-through
            case 404:
                return new Error\InvalidRequest($msg, $param, $rcode, $rbody, $resp, $rheaders);
            case 401:
                return new Error\Authentication($msg, $rcode, $rbody, $resp, $rheaders);
            case 402:
                return new Error\Card($msg, $param, $code, $rcode, $rbody, $resp, $rheaders);
            case 403:
                return new Error\Permission($msg, $rcode, $rbody, $resp, $rheaders);
            case 429:
                return new Error\RateLimit($msg, $param, $rcode, $rbody, $resp, $rheaders);
            default:
                return new Error\Api($msg, $rcode, $rbody, $resp, $rheaders);
        }
    }
285167
protected function _createFormatTranslationException($message, $code = 0, \Exception $previous = null, $subject = null, TranslatorInterface $translator = null, $context = null, $params = null)
    {
        return new FormatTranslationException($message, $code, $previous, $subject, $translator, $context, $params);
    }
199302
public static function make($errorCode, $errorMessage)
    {
        $exception = Arr::get(self::$supported, $errorCode, Errors\Error::class);

        return new $exception($errorMessage, $errorCode);
    }
480935
public static function from(DriverInterface $driver, $message = '', $code = 0, \Exception $previous = null)
    {
        //make sure that empty arguments don't get passed to exceptions as
        //they have default messages and codes.
        $self = $message ? ($code ? new static($message, $code, $previous) : new static($message)) : new static();

        $self->setDriver($driver);

        return $self;
    }
58713
private static function createExceptionMessage(
        RequestException $previous,
        ResponseInterface $response = null
    ): string {
        if (!$response) {
            return $previous->getMessage();
        }

        try {
            $result = guzzle_json_decode((string) $response->getBody(), true);
            if (isset($result['message'])) {
                return $result['message'];
            }
        } catch (\InvalidArgumentException $e) {
            return $previous->getMessage();
        }

        return $previous->getMessage();
    }
62015
public static DecodingException createDecodingException(
			final ErrorKeys errorId, final String message)
	{

		return new DecodingException(errorId.toString() + ":\r\n" + message);
	}
303000
private function getPaysafeException($httpCode, $message = null, $code = null)
    {
        if(!$message) {
            $message = "An unknown error has occurred.";
        }
        if(!$code) {
            $code = $httpCode;
        }

        $exceptionType = '\Paysafe\PaysafeException';
        switch($httpCode) {
            case '400':
                $exceptionType = '\Paysafe\InvalidRequestException';
                break;
            case '401':
                $exceptionType = '\Paysafe\InvalidCredentialsException';
                break;
            case '402':
                $exceptionType = '\Paysafe\RequestDeclinedException';
                break;
            case '403':
                $exceptionType = '\Paysafe\PermissionException';
                break;
            case '404':
                $exceptionType = '\Paysafe\EntityNotFoundException';
                break;
            case '409':
                $exceptionType = '\Paysafe\RequestConflictException';
                break;
            case '406':
            case '415':
                $exceptionType = '\Paysafe\APIException';
                break;
            default:
                if($httpCode >= 500) {
                    $exceptionType = '\Paysafe\APIException';
                }
                break;

        }

        return new $exceptionType($message,$code);
    }
1250241
public function exception($message = 'Undefined Exception', $type = null, $code = null)
    {
        if ($type === null) {
            $type = $this->default_exception;
        } elseif ($type[0] == '_') {
            if ($this->default_exception == 'BaseException') {
                $type = 'Exception_'.substr($type, 1);
            } else {
                $type = $this->default_exception.'_'.substr($type, 1);
            }
        } elseif ($type != 'BaseException') {
            $type = $this->app->normalizeClassName($type, 'Exception');
        }

        // Localization support
        $message = $this->app->_($message);

        if ($type == 'Exception') {
            $type = 'BaseException';
        }

        $e = new $type($message, $code);
        if (!($e instanceof BaseException)) {
            throw $e;
        }
        $e->owner = $this;
        $e->app = $this->app;
        $e->api = $this->app; // compatibility with ATK 4.2 and lower
        $e->init();

        return $e;
    }
487937
public static function create(
        $expected,
        $actual,
        $paramNo = null,
        $code = null,
        $previous = null
    ) {
        $msgMsk = 'Expected %1$s. Got %2$s';

        if ($paramNo !== null) {
            $msgMsk = 'Param #%3$s '.lcfirst($msgMsk);
        }

        if ($code !== null) {
            $msgMsk = '[%4$s] '.$msgMsk;
        }

        $class = get_called_class();
        return new $class(
            sprintf(
                $msgMsk,
                $expected,
                Debug::summarise($actual),
                $paramNo,
                $code
            ),
            is_int($code) ? $code : null,
            $previous
        );
    }