Skip to content

Commit

Permalink
faultMessage method
Browse files Browse the repository at this point in the history
  • Loading branch information
Andygrond committed Jul 13, 2023
1 parent bea6972 commit 06496f4
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions lib/Traits/Fault.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,20 +231,28 @@ trait Fault
],
];

public function faultMessage($code, $lang = 'en')
{
if (isset(self::$httpStatusCodes[$code])) {
if ($lang == false) {
http_response_code((int) $code);
}
return self::$httpStatusCodes[$code][$lang]?? self::$httpStatusCodes[$code]['s'];
}
return '';
}

// get the last json error
public function fault($code, $message = '', $lang = 'en')
{
if (isset(self::$httpStatusCodes[$code])) {
http_response_code($code);
if (!$message) {
$message = self::$httpStatusCodes[$code][$lang]?? self::$httpStatusCodes[$code]['s'];
}
http_response_code((int) $code);
}

return [
'fault' => [
'code' => $code,
'message' => $message,
'message' => $message?: $this->message($code, $lang),
]
];
}
Expand Down

0 comments on commit 06496f4

Please sign in to comment.