422, self::PHOTO_EXPIRED => 410, self::PRODUCT_UNAVAILABLE => 422, self::UNAVAILABLE => 503, self::BUSY => 409, self::NOT_FOUND => 404, self::STORAGE_FAILED => 500, self::BAD_REQUEST => 400, self::LIMIT_REACHED => 429, ); /** * One of the constants above. * * @var string */ private $error_code; /** * Finer reason, e.g. an InvalidImage reason, or empty. * * @var string */ private $detail; /** * Creates the error. * * @param string $code One of the constants above. * @param string $detail Finer reason, or empty. */ public function __construct( string $code, string $detail = '' ) { parent::__construct( 'Fitzaro API error: ' . $code ); $this->error_code = isset( self::STATUS[ $code ] ) ? $code : self::BAD_REQUEST; $this->detail = $detail; } /** * Error code. */ public function code(): string { return $this->error_code; } /** * Finer reason, or empty. */ public function detail(): string { return $this->detail; } /** * HTTP status. */ public function status(): int { return self::STATUS[ $this->error_code ]; } }