PluginProbe
Depicter — Popup & Slider Builder / 1.9.2
Depicter — Popup & Slider Builder v1.9.2
4.8.1 trunk 1.0.0 1.1.0 1.1.2 1.1.4 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.5 1.3.8 1.5.0 1.5.1 1.5.2 1.5.5 1.6.0 1.6.1 1.6.2 1.7.0 All 76 releases
← All changes | app/src/Utility/Http.php +22 -0 1.2.01.9.2 View file →
@@ -1,7 +1,10 @@
1 1 <?php
2 2 namespace Depicter\Utility;
3 3
4 +use Psr\Http\Message\ResponseInterface;
5 +
6 +
4 7 class Http {
5 8
6 9 public static function getErrorExceptionResponse( \Exception $exception ){
7 10 $isConnectionError = method_exists( $exception, 'getHandlerContext' );
@@ -30,8 +33,27 @@
30 33 }
31 34 if( ! empty( $error['context']['errno'] ) ){
32 35 $error['errCode'] = $error['context']['errno'];
33 36 }
37 + if( $error['errCode'] == 401 ){
38 + $error['message'] = "You are not authorized to access this resource.";
39 + }
34 40
35 41 return $error;
42 + }
43 +
44 + /**
45 + * Generate a Json response based on errors variable
46 + *
47 + * @param $errors
48 + *
49 + * @return ResponseInterface
50 + */
51 + public static function getErrorJson( $errors ){
52 + $errors = (array) $errors;
53 + $statusCode = (int) ( !empty( $errors['code'] ) ? $errors['code'] : 200 );
54 +
55 + return \Depicter::json([
56 + 'errors' => $errors
57 + ])->withStatus( max( $statusCode, 200 ) );
36 58 }
37 59 }