nur-sery/nur_src/b/CurlException.php

22 lines
620 B
PHP
Raw Normal View History

2023-12-03 22:10:18 +04:00
<?php
namespace nur\b;
use Throwable;
class CurlException extends UserException {
function __construct($ch, ?string $message=null, $code=0, ?Throwable $previous=null) {
$user_msg = $message;
if ($message === null) $message = "(unknown error)";
$tech_msg = null;
if ($ch !== null) {
$parts = [];
$errno = curl_errno($ch);
if ($errno != 0) $parts[] = "errno: $errno";
$error = curl_error($ch);
if ($error != "") $parts[] = "error: $error";
if ($parts) $tech_msg = implode(", ", $parts);
}
parent::__construct([$user_msg, $tech_msg], $code, $previous);
}
}