Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
8df748ef
Commit
8df748ef
authored
May 25, 2023
by
Alejandro Celaya
Committed by
Alejandro Celaya
May 25, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Migrate fetch module to TS
parent
51fc42a3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
12 deletions
+17
-12
fetch.ts
src/sidebar/util/fetch.ts
+17
-12
No files found.
src/sidebar/util/fetch.
j
s
→
src/sidebar/util/fetch.
t
s
View file @
8df748ef
...
...
@@ -8,16 +8,19 @@
* - Failures to parse the response in the expected format (eg. JSON)
*/
export
class
FetchError
extends
Error
{
url
:
string
;
response
:
Response
|
null
;
reason
:
string
;
/**
* @param {string} url - The URL that was requested. This may be different
* than the final URL of the response if a redirect happened.
* @param {Response|null} response - The response to the `fetch` request or
* `null` if the fetch failed
* @param {string} [reason] - Additional details about the error. This might
* include context of the network request or a server-provided error in
* the response.
* @param url - The URL that was requested. This may be different than the
* final URL of the response if a redirect happened.
* @param response - The response to the `fetch` request or `null` if the
* fetch failed
* @param reason - Additional details about the error. This might include
* context of the network request or a server-provided error in the response.
*/
constructor
(
url
,
response
,
reason
=
''
)
{
constructor
(
url
:
string
,
response
:
Response
|
null
,
reason
=
''
)
{
let
message
=
'Network request failed'
;
if
(
response
)
{
message
+=
` (
${
response
.
status
}
)`
;
...
...
@@ -39,13 +42,15 @@ export class FetchError extends Error {
* fetchJSON wraps the browser's `fetch` API to standardize error handling when
* making network requests that return JSON responses.
*
* @param {string} url
* @param {RequestInit} [init] - Parameters for `fetch` request
* @return {Promise<unknown>} - Parsed JSON response or `null` if response status is 204 (No Content)
* @param init - Parameters for `fetch` request
* @return Parsed JSON response or `null` if response status is 204 (No Content)
* @throws {FetchError} if the request fails, returns a non-2xx status or a JSON
* response is expected but cannot be parsed
*/
export
async
function
fetchJSON
(
url
,
init
)
{
export
async
function
fetchJSON
(
url
:
string
,
init
?:
RequestInit
):
Promise
<
unknown
>
{
let
response
;
try
{
response
=
await
fetch
(
url
,
init
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment