@@ -25,10 +25,12 @@ trait Responsible
25
25
* @var string
26
26
*/
27
27
protected $ message = null ;
28
+
28
29
/**
29
30
* @var array|null
30
31
*/
31
32
protected $ data = null ;
33
+
32
34
/**
33
35
* @var array|string|null
34
36
*/
@@ -83,6 +85,7 @@ public function setMessage($message, $mode = null)
83
85
return $ this ;
84
86
}
85
87
88
+
86
89
/**
87
90
* set data for respond ['data' => $data]
88
91
*
@@ -95,6 +98,7 @@ public function setRespondData($data)
95
98
return $ this ;
96
99
}
97
100
101
+
98
102
/**
99
103
* appendData
100
104
*
@@ -107,6 +111,7 @@ public function appendRespondData(array $data)
107
111
return $ this ;
108
112
}
109
113
114
+
110
115
/**
111
116
* set data for response ['error' => $error | (string) or (array)]
112
117
*
@@ -119,6 +124,7 @@ public function setRespondError($error)
119
124
return $ this ;
120
125
}
121
126
127
+
122
128
/**
123
129
* get data of sending respond
124
130
*
@@ -129,6 +135,7 @@ public function getRespondData()
129
135
return $ this ->data ;
130
136
}
131
137
138
+
132
139
/**
133
140
* get error of sending respond
134
141
*
@@ -213,10 +220,12 @@ public function respondDeleted()
213
220
*/
214
221
public function respondBadRequest ()
215
222
{
223
+ if (is_null ($ this ->getMessage ()))
224
+ $ this ->setMessage (trans ("responder::messages.error " ));
225
+
216
226
return $ this ->respond ([
217
227
"status " => "error " ,
218
228
"status_code " => Res::HTTP_BAD_REQUEST ,
219
- "message " => trans ("responder::messages.error " ),
220
229
]);
221
230
}
222
231
@@ -226,9 +235,9 @@ public function respondBadRequest()
226
235
*/
227
236
public function respondNotFound ()
228
237
{
229
- is_null ($ this ->getMessage ()) ?
230
- $ this ->setMessage (trans ("responder::messages.notfound " ))
231
- : $ this -> getMessage ();
238
+ if ( is_null ($ this ->getMessage ()))
239
+ $ this ->setMessage (trans ("responder::messages.notfound " ));
240
+
232
241
return $ this ->respond ([
233
242
'status ' => 'error ' ,
234
243
'status_code ' => Res::HTTP_NOT_FOUND ,
@@ -241,9 +250,9 @@ public function respondNotFound()
241
250
*/
242
251
public function respondInternalError ()
243
252
{
244
- is_null ($ this ->getMessage ()) ?
245
- $ this ->setMessage (trans ("responder::messages.internal_error " ))
246
- : $ this -> getMessage ();
253
+ if ( is_null ($ this ->getMessage ()))
254
+ $ this ->setMessage (trans ("responder::messages.internal_error " ));
255
+
247
256
return $ this ->respond ([
248
257
'status ' => 'error ' ,
249
258
'status_code ' => Res::HTTP_INTERNAL_SERVER_ERROR ,
@@ -258,9 +267,9 @@ public function respondInternalError()
258
267
*/
259
268
public function respondValidationError ($ errors = [])
260
269
{
261
- is_null ($ this ->getMessage ()) ?
262
- $ this ->setMessage (trans ("responder::messages.validation_error " ))
263
- : $ this -> getMessage ();
270
+ if ( is_null ($ this ->getMessage ()))
271
+ $ this ->setMessage (trans ("responder::messages.validation_error " ));
272
+
264
273
return $ this ->respond ([
265
274
'status ' => 'error ' ,
266
275
'status_code ' => Res::HTTP_UNPROCESSABLE_ENTITY ,
@@ -276,6 +285,9 @@ public function respondValidationError($errors = [])
276
285
*/
277
286
public function respondUnauthorizedError ()
278
287
{
288
+ if (is_null ($ this ->getMessage ()))
289
+ $ this ->setMessage (trans ("responder::messages.unauthenticated " ));
290
+
279
291
return $ this ->respond ([
280
292
"status " => "error " ,
281
293
"status_code " => Res::HTTP_UNAUTHORIZED ,
0 commit comments