Template
Erreurs sous /api/ : page visuelle dans le navigateur, JSON pour curl
Négociation de contenu via l'en-tête Accept : un navigateur (text/html explicite) reçoit la page 404 du site, tout autre client (curl, scripts, apps) reçoit le JSON. S'applique aux 404 doux et aux réponses du filet d'erreurs PHP.
This commit is contained in:
1 parent
82168e2678
commit
6b6b07aa83
2 files changed
+15
-9
No files matched your search
@@ -70,9 +70,10 @@ if (in_array((int) ($_GET['__e'] ?? 0), [403, 404], true)) {
|
||||
$is404 = true;
|
||||
header('Access-Control-Allow-Origin: *');
|
||||
header('Cache-Control: no-store');
|
||||
/* Chemins API : réponse JSON (jamais de HTML ni de détail technique). */
|
||||
/* Chemins API : JSON pour curl/scripts, page visuelle pour un navigateur
|
||||
* (négociation via Accept, comme inc/errors.php). */
|
||||
$reqPath = (string) (parse_url((string) ($_SERVER['REQUEST_URI'] ?? '/'), PHP_URL_PATH) ?: '/');
|
||||
if (str_starts_with($reqPath, '/api')) {
|
||||
if (str_starts_with($reqPath, '/api') && fws_error_wants_json()) {
|
||||
http_response_code(404);
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
header('X-Content-Type-Options: nosniff');
|
||||
|
||||
Reference in new issue
Block a user