agraboso / agraboso/redux-api-middleware

How to detect timeout or refused connection?

Offen
#135 8 Kommentare 3 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
question
Vorherrschende Sprache
JavaScript
Sterne
1.5k
Forks
190
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

I have something like this:
```
//...
return {
[CALL_API]: {
endpoint,
method,
types: [
types.API_POST_CREDENTIALS_REQUEST,
{
type: types.API_POST_CREDENTIALS_SUCCESS,
payload: (action, state, res) => apiUpdateSuccess(action, state, res)
},
{
type: types.API_POST_CREDENTIALS_FAILURE,
payload: (action, state, res) => apiUpdateFailure(action, state, res)
}
],
headers: {'Content-Type': 'application/json'},
body: JSON.stringify(payload)
}
};
//...

function apiUpdateSuccess(action, state, res) {
return getJSON(res).then((data) => {
return data;
});
}

function apiUpdateFailure(action, state, res) {
return getJSON(res).then((data) => {
return data;
});
}
```

But when the API is offline or a request times out, neither apiUpdateSuccess nor apiUpdateFailure is fired. What would be the best practice to detect timeout and offline API?

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.