-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #378 from docknetwork/feat/remove-axios
Remove Axios in favor of fetch
- Loading branch information
Showing
14 changed files
with
84 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
export class JSONFetchError extends Error { | ||
constructor(message, statusCode) { | ||
super(message); | ||
|
||
this.statusCode = statusCode; | ||
} | ||
} | ||
|
||
export default async function jsonFetch(url, options) { | ||
if (url.startsWith('blob:')) { | ||
throw new Error('Unsupported protocol blob:'); | ||
} | ||
|
||
let response; | ||
try { | ||
response = await fetch(url, options); | ||
} catch (e) { | ||
throw new Error(`Fetch failed for URL: ${url}`); | ||
} | ||
if (response.ok) { | ||
let doc; | ||
try { | ||
doc = await response.json(); | ||
} catch (e) { | ||
throw new Error(`URL: ${url} is not JSON`); | ||
} | ||
return doc; | ||
} else { | ||
// Handle the case when the fetch request fails (e.g., non-2xx response status) | ||
throw new JSONFetchError('Failed to fetch data', response.status); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import networkCache from '../network-cache'; | ||
|
||
// Mock the global fetch function | ||
global.fetch = jest.fn(); | ||
|
||
// Function to set up a mock response for fetch | ||
const mockFetchResponse = (status, data) => { | ||
const response = new Response(JSON.stringify(data), { | ||
status, | ||
headers: { | ||
'Content-type': 'application/json', | ||
}, | ||
}); | ||
return Promise.resolve(response); | ||
}; | ||
|
||
export default function mockFetch() { | ||
// Set up a mock response for all GET requests | ||
fetch.mockImplementation((url) => { | ||
if (networkCache[url]) { | ||
return mockFetchResponse(200, networkCache[url]); | ||
} | ||
|
||
console.error(`Test should cache this URL: ${url}`); | ||
throw new Error(`Test should cache this URL: ${url}`); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4733,14 +4733,6 @@ aws4@^1.8.0: | |
resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.11.0.tgz#d61f46d83b2519250e2784daf5b09479a8b41c59" | ||
integrity sha512-xh1Rl34h6Fi1DC2WWKfxUTVqRsNnr6LsKz2+hfwDxQJWmrx8+c7ylaqBMcHfl1U1r2dsifOvKX3LQuLNZ+XSvA== | ||
|
||
[email protected]: | ||
version "0.27.2" | ||
resolved "https://registry.yarnpkg.com/axios/-/axios-0.27.2.tgz#207658cc8621606e586c85db4b41a750e756d972" | ||
integrity sha512-t+yRIyySRTp/wua5xEr+z1q60QmLq8ABsS5O9Me1AsE5dfKqgnCFzwiCZZ/cGNd1lq4/7akDWMxdhVlucjmnOQ== | ||
dependencies: | ||
follow-redirects "^1.14.9" | ||
form-data "^4.0.0" | ||
|
||
b4a@^1.0.1: | ||
version "1.6.1" | ||
resolved "https://registry.yarnpkg.com/b4a/-/b4a-1.6.1.tgz#9effac93a469a868d024e16fd77162c653544cbd" | ||
|
@@ -7086,7 +7078,7 @@ [email protected]: | |
resolved "https://registry.yarnpkg.com/fn.name/-/fn.name-1.1.0.tgz#26cad8017967aea8731bc42961d04a3d5988accc" | ||
integrity sha512-GRnmB5gPyJpAhTQdSZTSp9uaPSvl09KoYcMQtsB9rQoOmzs9dH6ffeccH+Z+cv6P68Hu5bC6JjRh4Ah/mHSNRw== | ||
|
||
follow-redirects@^1.14.9, follow-redirects@^1.5.1: | ||
follow-redirects@^1.5.1: | ||
version "1.15.2" | ||
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.2.tgz#b460864144ba63f2681096f274c4e57026da2c13" | ||
integrity sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA== | ||
|