1 | <?php |
||
5 | trait ErrorResponsesTrait |
||
6 | { |
||
7 | /** |
||
8 | * Returns a response that indicates an an error occurred. |
||
9 | * |
||
10 | * @param $message |
||
11 | * @param int $statusCode |
||
12 | * @return \Illuminate\Http\JsonResponse |
||
13 | */ |
||
14 | private function respondWithError($message, $statusCode = 400) |
||
23 | |||
24 | /** |
||
25 | * Returns a response that indicates a 403 Forbidden. |
||
26 | * |
||
27 | * @param string $message |
||
28 | * @return \Illuminate\Http\JsonResponse |
||
29 | */ |
||
30 | protected function errorForbidden($message = 'Forbidden') |
||
34 | |||
35 | /** |
||
36 | * Returns a response that indicates an Internal Error has occurred. |
||
37 | * |
||
38 | * @param string $message |
||
39 | * @return \Illuminate\Http\JsonResponse |
||
40 | */ |
||
41 | protected function errorInternalError($message = 'Internal Error') |
||
45 | |||
46 | /** |
||
47 | * Returns a response that indicates a 404 Not Found. |
||
48 | * |
||
49 | * @param string $message |
||
50 | * @return \Illuminate\Http\JsonResponse |
||
51 | */ |
||
52 | protected function errorNotFound($message = 'Resource Not Found') |
||
56 | |||
57 | /** |
||
58 | * Returns a response that indicates a 401 Unauthorized. |
||
59 | * |
||
60 | * @param string $message |
||
61 | * @return \Illuminate\Http\JsonResponse |
||
62 | */ |
||
63 | protected function errorUnauthorized($message = 'Unauthorized') |
||
67 | |||
68 | /** |
||
69 | * Returns a response that indicates a 422 Unprocessable Entity. |
||
70 | * |
||
71 | * @param string $message |
||
72 | * @return \Illuminate\Http\JsonResponse |
||
73 | */ |
||
74 | protected function errorUnprocessableEntity($message = 'Unprocessable Entity') |
||
78 | |||
79 | /** |
||
80 | * Returns a response that indicates the wrong arguments were specified. |
||
81 | * |
||
82 | * @param string $message |
||
83 | * @return \Illuminate\Http\JsonResponse |
||
84 | */ |
||
85 | protected function errorWrongArgs($message = 'Wrong Arguments') |
||
89 | |||
90 | /** |
||
91 | * Returns a response that indicates custom error type. |
||
92 | * |
||
93 | * @param $message |
||
94 | * @param $statusCode |
||
95 | * @return \Illuminate\Http\JsonResponse |
||
96 | */ |
||
97 | protected function errorCustomType($message, $statusCode = 400) |
||
101 | |||
102 | /** |
||
103 | * Returns a response that indicates multiple errors in an array. |
||
104 | * |
||
105 | * @param array $errors |
||
106 | * @param $statusCode |
||
107 | * @return \Illuminate\Http\JsonResponse |
||
108 | */ |
||
109 | protected function errorArray(array $errors, $statusCode = 400) |
||
115 | |||
116 | /** |
||
117 | * Returns a response that mimics Laravel validation failure response. |
||
118 | * |
||
119 | * @param array $errors |
||
120 | * @return \Illuminate\Http\JsonResponse |
||
121 | */ |
||
122 | protected function errorValidation(array $errors) |
||
126 | } |