Skip to content

Commit 2df56c0

Browse files
authored
Merge pull request #542 from sebj54/fix-router-error
Add a default error in SimpleRouter
2 parents f28ee9b + df2472b commit 2df56c0

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

api.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4590,6 +4590,8 @@ public function handle(ServerRequestInterface $request): ResponseInterface
45904590
$response = $this->responder->error(ErrorCode::DATA_INTEGRITY_VIOLATION, '');
45914591
} elseif (strpos(strtolower($e->getMessage()), 'constraint') !== false) {
45924592
$response = $this->responder->error(ErrorCode::DATA_INTEGRITY_VIOLATION, '');
4593+
} else {
4594+
$response = $this->responder->error(ErrorCode::ERROR_NOT_FOUND, '');
45934595
}
45944596
if ($this->debug) {
45954597
$response = ResponseUtils::addExceptionHeaders($response, $e);
@@ -7430,7 +7432,7 @@ public static function output(ResponseInterface $response)
74307432
public static function addExceptionHeaders(ResponseInterface $response, \Throwable $e): ResponseInterface
74317433
{
74327434
$response = $response->withHeader('X-Exception-Name', get_class($e));
7433-
$response = $response->withHeader('X-Exception-Message', $e->getMessage());
7435+
$response = $response->withHeader('X-Exception-Message', preg_replace('|\n|', ' ', trim($e->getMessage())));
74347436
$response = $response->withHeader('X-Exception-File', $e->getFile() . ':' . $e->getLine());
74357437
return $response;
74367438
}

src/Tqdev/PhpCrudApi/Middleware/Router/SimpleRouter.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ public function handle(ServerRequestInterface $request): ResponseInterface
125125
$response = $this->responder->error(ErrorCode::DATA_INTEGRITY_VIOLATION, '');
126126
} elseif (strpos(strtolower($e->getMessage()), 'constraint') !== false) {
127127
$response = $this->responder->error(ErrorCode::DATA_INTEGRITY_VIOLATION, '');
128+
} else {
129+
$response = $this->responder->error(ErrorCode::ERROR_NOT_FOUND, '');
128130
}
129131
if ($this->debug) {
130132
$response = ResponseUtils::addExceptionHeaders($response, $e);

0 commit comments

Comments
 (0)