diff --git a/src/ApiResponse/ApiResponse.php b/src/ApiResponse/ApiResponse.php index cd7ca2e..b726e15 100644 --- a/src/ApiResponse/ApiResponse.php +++ b/src/ApiResponse/ApiResponse.php @@ -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'] + ); + } }