Skip to content

Commit fde9f63

Browse files
committed
fix: implement custom error rendering with JSON response and CORS headers
1 parent 8e26ca6 commit fde9f63

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

app/Error/Error.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace App\Error;
44

5+
use App\Response\JsonResponse;
56
use Core\Support\Error as BaseError;
67

78
class Error extends BaseError
@@ -13,8 +14,14 @@ class Error extends BaseError
1314
*/
1415
public function render(): mixed
1516
{
16-
//
17+
$res = new JsonResponse();
18+
$res->headers->set('Access-Control-Allow-Origin', '*');
19+
$res->headers->set('Access-Control-Allow-Methods', '*');
1720

18-
return parent::render();
21+
if (!debug()) {
22+
return $res->errorServer();
23+
}
24+
25+
return $res->error([$this->getThrowable()->getMessage()], JsonResponse::HTTP_INTERNAL_SERVER_ERROR);
1926
}
2027
}

0 commit comments

Comments
 (0)