Skip to content

Commit

Permalink
Merge pull request #4 from MRizki28/test2
Browse files Browse the repository at this point in the history
add error method
  • Loading branch information
MRizki28 authored Aug 9, 2024
2 parents ea99b50 + c99fe76 commit baa8159
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/ApiResponse/ApiResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,24 @@ public static function notFound($message = 'Data not found', int $code = 404)
['Content-Type' => 'application/json']
);
}

/**
* Format an error response.
*
* @param string $message Message to include in the response.
* @param int $code HTTP status code.
* @return string JSON formatted response.
*/

public static function error( \Throwable $th = null, $message = 'Error', int $code = 500,){
return new Response(
json_encode([
'status' => 'error',
'message' => $message,
'error' => $th
]),
$code,
['Content-Type' => 'application/json']
);
}
}

0 comments on commit baa8159

Please sign in to comment.