@@ -25,10 +25,12 @@ trait Responsible
2525 * @var string
2626 */
2727 protected $ message = null ;
28+
2829 /**
2930 * @var array|null
3031 */
3132 protected $ data = null ;
33+
3234 /**
3335 * @var array|string|null
3436 */
@@ -83,6 +85,7 @@ public function setMessage($message, $mode = null)
8385 return $ this ;
8486 }
8587
88+
8689 /**
8790 * set data for respond ['data' => $data]
8891 *
@@ -95,6 +98,7 @@ public function setRespondData($data)
9598 return $ this ;
9699 }
97100
101+
98102 /**
99103 * appendData
100104 *
@@ -107,6 +111,7 @@ public function appendRespondData(array $data)
107111 return $ this ;
108112 }
109113
114+
110115 /**
111116 * set data for response ['error' => $error | (string) or (array)]
112117 *
@@ -119,6 +124,7 @@ public function setRespondError($error)
119124 return $ this ;
120125 }
121126
127+
122128 /**
123129 * get data of sending respond
124130 *
@@ -129,6 +135,7 @@ public function getRespondData()
129135 return $ this ->data ;
130136 }
131137
138+
132139 /**
133140 * get error of sending respond
134141 *
@@ -213,10 +220,12 @@ public function respondDeleted()
213220 */
214221 public function respondBadRequest ()
215222 {
223+ if (is_null ($ this ->getMessage ()))
224+ $ this ->setMessage (trans ("responder::messages.error " ));
225+
216226 return $ this ->respond ([
217227 "status " => "error " ,
218228 "status_code " => Res::HTTP_BAD_REQUEST ,
219- "message " => trans ("responder::messages.error " ),
220229 ]);
221230 }
222231
@@ -226,9 +235,9 @@ public function respondBadRequest()
226235 */
227236 public function respondNotFound ()
228237 {
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+
232241 return $ this ->respond ([
233242 'status ' => 'error ' ,
234243 'status_code ' => Res::HTTP_NOT_FOUND ,
@@ -241,9 +250,9 @@ public function respondNotFound()
241250 */
242251 public function respondInternalError ()
243252 {
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+
247256 return $ this ->respond ([
248257 'status ' => 'error ' ,
249258 'status_code ' => Res::HTTP_INTERNAL_SERVER_ERROR ,
@@ -258,9 +267,9 @@ public function respondInternalError()
258267 */
259268 public function respondValidationError ($ errors = [])
260269 {
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+
264273 return $ this ->respond ([
265274 'status ' => 'error ' ,
266275 'status_code ' => Res::HTTP_UNPROCESSABLE_ENTITY ,
@@ -276,6 +285,9 @@ public function respondValidationError($errors = [])
276285 */
277286 public function respondUnauthorizedError ()
278287 {
288+ if (is_null ($ this ->getMessage ()))
289+ $ this ->setMessage (trans ("responder::messages.unauthenticated " ));
290+
279291 return $ this ->respond ([
280292 "status " => "error " ,
281293 "status_code " => Res::HTTP_UNAUTHORIZED ,
0 commit comments