diff --git a/src/ApiResponse/ApiResponse.php b/src/ApiResponse/ApiResponse.php index b726e15..4f1ee9d 100644 --- a/src/ApiResponse/ApiResponse.php +++ b/src/ApiResponse/ApiResponse.php @@ -56,14 +56,25 @@ public static function notFound($message = 'Data not found', int $code = 404) * @param string $message Message to include in the response. * @param int $code HTTP status code. * @return string JSON formatted response. + * @param \Throwable|null only method Throwable */ - public static function error( \Throwable $th = null, $message = 'Error', int $code = 500,){ + public static function error(\Throwable $th = null, $message = 'Error', int $code = 500,) + { + $errorDetail = null; + if ($th) { + $errorDetail = [ + 'message' => $th->getMessage(), + 'file' => $th->getFile(), + 'line' => $th->getLine(), + 'trace' => $th->getTrace() + ]; + } return new Response( json_encode([ 'status' => 'error', 'message' => $message, - 'error' => $th + 'error' => $errorDetail ]), $code, ['Content-Type' => 'application/json']