generated from deco-sites/start
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
split fetch/fetch.server to avoid breaking (#219)
- Loading branch information
Showing
21 changed files
with
77 additions
and
39 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
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 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 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 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,31 @@ | ||
import * as fetcher from "https://denopkg.com/deco-cx/[email protected]/utils/fetch.ts"; | ||
|
||
export interface FetchOptions { | ||
withProxyCache?: boolean; | ||
} | ||
|
||
export const fetchSafe = ( | ||
input: string | Request | URL, | ||
init?: RequestInit & FetchOptions, | ||
) => | ||
fetcher.fetchSafe(input, { | ||
...init, | ||
deco: init?.withProxyCache | ||
? { | ||
cache: "stale-while-revalidate", | ||
} | ||
: undefined, | ||
}); | ||
|
||
export const fetchAPI = <T>( | ||
input: string | Request | URL, | ||
init?: RequestInit & FetchOptions, | ||
): Promise<T> => | ||
fetcher.fetchAPI(input, { | ||
...init, | ||
deco: init?.withProxyCache | ||
? { | ||
cache: "stale-while-revalidate", | ||
} | ||
: undefined, | ||
}); |
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 |
---|---|---|
|
@@ -3,7 +3,10 @@ import { | |
assertSpyCalls, | ||
spy, | ||
} from "https://deno.land/[email protected]/testing/mock.ts"; | ||
import { CONNECTION_CLOSED_MESSAGE, retryExceptionOr500 } from "./fetch.ts"; | ||
import { | ||
CONNECTION_CLOSED_MESSAGE, | ||
retryExceptionOr500, | ||
} from "./fetch.server.ts"; | ||
import { assertEquals } from "https://deno.land/[email protected]/testing/asserts.ts"; | ||
|
||
Deno.test("retry handler", async (t) => { | ||
|
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 |
---|---|---|
@@ -1,31 +1,35 @@ | ||
import * as fetcher from "https://denopkg.com/deco-cx/[email protected]/utils/fetch.ts"; | ||
import { HttpError } from "deco-sites/std/utils/HttpError.ts"; | ||
|
||
export interface FetchOptions { | ||
withProxyCache?: boolean; | ||
} | ||
|
||
export const fetchSafe = ( | ||
export const fetchSafe = async ( | ||
input: string | Request | URL, | ||
init?: RequestInit & FetchOptions, | ||
) => | ||
fetcher.fetchSafe(input, { | ||
...init, | ||
deco: init?.withProxyCache | ||
? { | ||
cache: "stale-while-revalidate", | ||
} | ||
: undefined, | ||
}); | ||
) => { | ||
const response = await fetch(input, init); | ||
|
||
if (response.ok) { | ||
return response; | ||
} | ||
|
||
console.error(`${input}\n`, response, `\n`); | ||
throw new HttpError(response.status, `${input}`); | ||
}; | ||
|
||
export const fetchAPI = <T>( | ||
export const fetchAPI = async <T>( | ||
input: string | Request | URL, | ||
init?: RequestInit & FetchOptions, | ||
): Promise<T> => | ||
fetcher.fetchAPI(input, { | ||
): Promise<T> => { | ||
const headers = new Headers(init?.headers); | ||
|
||
headers.set("accept", "application/json"); | ||
|
||
const response = await fetchSafe(input, { | ||
...init, | ||
deco: init?.withProxyCache | ||
? { | ||
cache: "stale-while-revalidate", | ||
} | ||
: undefined, | ||
headers, | ||
}); | ||
|
||
return response.json(); | ||
}; |
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