-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4df6e4d
commit 2e9e0be
Showing
3 changed files
with
33 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,19 @@ | ||
export const proxyFetch = (url: string) => | ||
fetch(`https://api.codetabs.com/v1/proxy/?quest=${url}`, undefined).then( | ||
(res) => { | ||
if (!res.ok) throw new Error(`Could not load ${url}`) | ||
// TODO - handle 404s/pageful errors | ||
// if (res.status === 404) return null | ||
return res.text() | ||
}, | ||
import { PreviewError, errorType } from './errors' | ||
|
||
export async function proxyFetch(url: string) { | ||
const res = await fetch( | ||
`https://api.codetabs.com/v1/proxy/?quest=${url}`, | ||
undefined, | ||
) | ||
|
||
if (!res.ok) | ||
throw new PreviewError(`Could not load ${url}`, errorType.NETWORK_ERROR) | ||
|
||
const raw = await res.text() | ||
|
||
if (res.status === 404 || raw.includes('<title>Not Found</title>')) | ||
// Manually check for this title since Gitlab returns a 200 for non-existent files | ||
throw new PreviewError(`Could not load ${url}`, errorType.NOT_FOUND) | ||
|
||
return raw | ||
} |
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