posva / mande

<700 bytes convenient and modern wrapper around fetch with smart extensible defaults
https://mande.esm.is
MIT License
1.2k stars 42 forks source link

403 Forbidden Response Doesn't Throw Exception #469

Open XDGFX opened 6 months ago

XDGFX commented 6 months ago

I'm using mande to send a post request to a server. Sometimes the server returns a 403 response, so I expect the .post() method to throw an exception, however it doesn't.

Client side code:

try {
    const renew = mande(SERVER_URL + '/api/v1/token/renew');
    const res = await renew.post<ApiRes<'/token/renew', 'POST'>>();

    token = res.token;
    id = res.id;
    expires = res.expires;
} catch (error) {
    console.error('Failed to renew token:', error);
    logout();
    return;
}

However the catch block never runs, I get this error in the browser console

[XHR]POST.   http://localhost:3478/api/v1/token/renew.  [HTTP/1.1 403 Forbidden 34ms]

Using Firefox 125.0.3 on macOS.