Fix session-expiry redirect not showing login form
When Symfony returns a non-JSON body (empty or HTML) for a 401 on protected API routes, res.json() throws a SyntaxError with no .status, so showLogin() was never called. Now the HTTP status is preserved through JSON parse failures so the 401 check works correctly. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
f4b1e81065
commit
99304a6174
1 changed files with 3 additions and 0 deletions
|
|
@ -264,6 +264,9 @@ function api(method, path, body){
|
||||||
return res.json().then(function(data){
|
return res.json().then(function(data){
|
||||||
if(!res.ok){ var e=new Error(data.error||'Fehler'); e.status=res.status; throw e; }
|
if(!res.ok){ var e=new Error(data.error||'Fehler'); e.status=res.status; throw e; }
|
||||||
return data;
|
return data;
|
||||||
|
}).catch(function(e){
|
||||||
|
if(e.status){ throw e; }
|
||||||
|
var ne=new Error('Fehler'); ne.status=res.status; throw ne;
|
||||||
});
|
});
|
||||||
}).catch(function(e){
|
}).catch(function(e){
|
||||||
if(e.status===401 && path!=='login'){ showLogin(); }
|
if(e.status===401 && path!=='login'){ showLogin(); }
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue