Skip to content

Commit

Permalink
fix() signal from axios.get is a specific AbortSignal (OpenStickCommu…
Browse files Browse the repository at this point in the history
…nity#1001)

* axios signal

* adapt to cancelling

* use error.name as identifier

* leave the special chainer in place since the reject is custom
  • Loading branch information
asturur authored May 7, 2024
1 parent 86c9b3f commit cdce584
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion www/src/Services/Http.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
// This is modeled after Axios to make an easier transition, so this may need more buildout
// if more than simple GET and POST requests are required.

type GetOptions = {
headers?: Record<string, string>,
signal?: AbortSignal
}

class Http {
async get(url: string, headers: object = {}) {
async get(url: string, { headers = {}, signal }: GetOptions = {}) {
try {
const response = await fetch(url, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
...headers,
},
signal
});

const json = await response.json();
Expand Down
2 changes: 1 addition & 1 deletion www/src/Services/WebApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ async function getHeldPins(abortSignal) {
});
return response.data;
} catch (error) {
if (error?.code === 'ERR_CANCELED') return { canceled: true };
if (error?.name === 'AbortError') return { canceled: true };
else console.error(error);
}
}
Expand Down

0 comments on commit cdce584

Please sign in to comment.