fix: Improve error handling untuk docs routes

This commit is contained in:
mwpn
2025-12-17 11:08:27 +07:00
parent c08e0c7983
commit c7bfaee618

View File

@@ -31,10 +31,10 @@ $app->get('/docs', function ($request, $response) {
$docsPath = __DIR__ . '/docs/index.html'; $docsPath = __DIR__ . '/docs/index.html';
if (!file_exists($docsPath)) { if (!file_exists($docsPath)) {
$response->getBody()->write('<h1>Documentation not found</h1>');
return $response return $response
->withStatus(404) ->withStatus(404)
->withHeader('Content-Type', 'text/html') ->withHeader('Content-Type', 'text/html');
->getBody()->write('<h1>Documentation not found</h1>');
} }
$html = file_get_contents($docsPath); $html = file_get_contents($docsPath);
@@ -48,10 +48,10 @@ $app->get('/docs/openapi.json', function ($request, $response) {
$openApiPath = __DIR__ . '/docs/openapi.json'; $openApiPath = __DIR__ . '/docs/openapi.json';
if (!file_exists($openApiPath)) { if (!file_exists($openApiPath)) {
$response->getBody()->write(json_encode(['error' => 'OpenAPI spec not found']));
return $response return $response
->withStatus(404) ->withStatus(404)
->withHeader('Content-Type', 'application/json') ->withHeader('Content-Type', 'application/json');
->getBody()->write(json_encode(['error' => 'OpenAPI spec not found']));
} }
$json = file_get_contents($openApiPath); $json = file_get_contents($openApiPath);