2020-06-07 11:24:15 +00:00
|
|
|
<?php
|
2021-11-18 04:24:30 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020-2021 Антон Аксенов (Anthony Axenov)
|
2020-06-07 11:24:15 +00:00
|
|
|
*
|
|
|
|
* This code is licensed under MIT.
|
|
|
|
* Этот код распространяется по лицензии MIT.
|
|
|
|
* https://github.com/anthonyaxenov/atol-online/blob/master/LICENSE
|
|
|
|
*/
|
|
|
|
|
2021-11-18 04:24:30 +00:00
|
|
|
declare(strict_types = 1);
|
|
|
|
|
2020-06-07 11:24:15 +00:00
|
|
|
namespace AtolOnline\Exceptions;
|
|
|
|
|
|
|
|
use AtolOnline\Api\KktResponse;
|
|
|
|
use Exception;
|
|
|
|
use Throwable;
|
|
|
|
|
|
|
|
/**
|
2021-11-17 16:01:53 +00:00
|
|
|
* Исключение, возникающее при неудачной авторизации
|
2020-06-07 11:24:15 +00:00
|
|
|
*/
|
2021-11-18 04:24:30 +00:00
|
|
|
class AuthFailedException extends Exception
|
2020-06-07 11:24:15 +00:00
|
|
|
{
|
|
|
|
/**
|
2021-11-18 04:24:30 +00:00
|
|
|
* Конструктор
|
2020-06-07 11:24:15 +00:00
|
|
|
*
|
2021-11-17 16:01:53 +00:00
|
|
|
* @param KktResponse $response
|
2021-11-18 04:24:30 +00:00
|
|
|
* @param string $message
|
|
|
|
* @param int $code
|
|
|
|
* @param Throwable|null $previous
|
2020-06-07 11:24:15 +00:00
|
|
|
*/
|
2021-11-17 16:01:53 +00:00
|
|
|
public function __construct(KktResponse $response, $message = "", $code = 0, Throwable $previous = null)
|
2020-06-07 11:24:15 +00:00
|
|
|
{
|
2021-11-17 16:01:53 +00:00
|
|
|
$message = $response->isValid()
|
2020-06-07 11:24:15 +00:00
|
|
|
? $message
|
2021-11-17 16:01:53 +00:00
|
|
|
: '[' . $response->error->code . '] ' . $response->error->text .
|
|
|
|
'. ERROR_ID: ' . $response->error->error_id .
|
|
|
|
'. TYPE: ' . $response->error->type;
|
|
|
|
$code = $response->isValid() ? $code : $response->error->code;
|
2020-06-07 11:24:15 +00:00
|
|
|
parent::__construct($message, $code, $previous);
|
|
|
|
}
|
2020-10-12 18:06:13 +00:00
|
|
|
}
|