| 1 |
<?php |
| 2 |
namespace Depicter\Utility; |
| 3 |
|
| 4 |
class Http { |
| 5 |
|
| 6 |
public static function getErrorExceptionResponse( \Exception $exception ){ |
| 7 |
$isConnectionError = method_exists( $exception, 'getHandlerContext' ); |
| 8 |
$errorClassInstance = get_class( $exception ); |
| 9 |
|
| 10 |
$error = [ |
| 11 |
'message' => $exception->getMessage(), |
| 12 |
'detail' => $exception->getMessage(), |
| 13 |
'errCode' => $exception->getCode(), |
| 14 |
'group' => 'Exception', // name of exception group |
| 15 |
'type' => basename( str_replace('\\', '/', $errorClassInstance )), // unqualified (short) exception class name |
| 16 |
'instance' => $errorClassInstance, |
| 17 |
'context' => null, |
| 18 |
'statusCode' => 500 |
| 19 |
]; |
| 20 |
|
| 21 |
if( $isConnectionError ){ |
| 22 |
$error['message'] = __( 'Connection Error ..', 'depicter' ); |
| 23 |
$error['group'] = 'RequestException'; |
| 24 |
$error['context'] = $exception->getHandlerContext(); |
| 25 |
$error['statusCode'] = 503; |
| 26 |
} |
| 27 |
|
| 28 |
if( ! empty( $error['context']['error'] ) ){ |
| 29 |
$error['detail'] = $error['context']['error']; |
| 30 |
} |
| 31 |
if( ! empty( $error['context']['errno'] ) ){ |
| 32 |
$error['errCode'] = $error['context']['errno']; |
| 33 |
} |
| 34 |
|
| 35 |
return $error; |
| 36 |
} |
| 37 |
} |
| 38 |
|