Skip to content

Commit

Permalink
Update error handler for better logging.
Browse files Browse the repository at this point in the history
  • Loading branch information
Meezaan-ud-Din committed Apr 16, 2019
1 parent b5746ad commit cca6cba
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/AlAdhanApi/Handler/AlAdhanHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
use AlAdhanApi\Helper\Log;
use Slim\Http\Request;
use Slim\Http\Response;
use Exception;

class AlAdhanHandler
{
public function __invoke(Request $request, Response $response, $exception = null) {
public function __invoke(Request $request, Response $response, Exception $exception) {

if ($exception instanceof WafKeyMismatchException) {
$r = [
Expand All @@ -21,15 +22,21 @@ public function __invoke(Request $request, Response $response, $exception = null
};

$r = [
'code' => 500,
'code' => $exception->getCode(),
'status' => 'Internal Server Error',
'data' => 'Something went wrong when the server tried to process this request. Sorry!'
];

$log = new Log();
$log->error( $exception->getCode() . ' : ' . $exception->getMessage() . ' | ' . $exception->getTraceAsString());

return $response->withJson($r, 500);
$log->error('AlAdhan Exception Triggered.',
[
'code' => $exception->getCode(),
'message' => $exception->getMessage(),
'trace' => $exception->getTraceAsString()
]
);

return $response->withJson($r, $exception->getCode());
}

}

0 comments on commit cca6cba

Please sign in to comment.