fix: Improve error handling untuk docs routes
This commit is contained in:
@@ -31,10 +31,10 @@ $app->get('/docs', function ($request, $response) {
|
||||
$docsPath = __DIR__ . '/docs/index.html';
|
||||
|
||||
if (!file_exists($docsPath)) {
|
||||
$response->getBody()->write('<h1>Documentation not found</h1>');
|
||||
return $response
|
||||
->withStatus(404)
|
||||
->withHeader('Content-Type', 'text/html')
|
||||
->getBody()->write('<h1>Documentation not found</h1>');
|
||||
->withHeader('Content-Type', 'text/html');
|
||||
}
|
||||
|
||||
$html = file_get_contents($docsPath);
|
||||
@@ -48,10 +48,10 @@ $app->get('/docs/openapi.json', function ($request, $response) {
|
||||
$openApiPath = __DIR__ . '/docs/openapi.json';
|
||||
|
||||
if (!file_exists($openApiPath)) {
|
||||
$response->getBody()->write(json_encode(['error' => 'OpenAPI spec not found']));
|
||||
return $response
|
||||
->withStatus(404)
|
||||
->withHeader('Content-Type', 'application/json')
|
||||
->getBody()->write(json_encode(['error' => 'OpenAPI spec not found']));
|
||||
->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
|
||||
$json = file_get_contents($openApiPath);
|
||||
|
||||
Reference in New Issue
Block a user