23 lines
671 B
PHP
23 lines
671 B
PHP
|
<?php
|
||
|
namespace nulib\web\ext;
|
||
|
|
||
|
use nulib\UserException;
|
||
|
use Throwable;
|
||
|
|
||
|
class CurlException extends UserException {
|
||
|
function __construct($ch, ?string $message=null, $code=0, ?Throwable $previous=null) {
|
||
|
$user_message = $message;
|
||
|
if ($message === null) $message = "(unknown error)";
|
||
|
$tech_message = 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_message = implode(", ", $parts);
|
||
|
}
|
||
|
parent::__construct($user_message, $tech_message, $code, $previous);
|
||
|
}
|
||
|
}
|