-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
add error handling to weather fetch functions, including cors #3791
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from 1 commit
6ee9a66
b5487c8
c0a84c5
518e986
96c8853
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,20 +17,26 @@ async function performWebRequest (url, type = "json", useCorsProxy = false, requ | |
requestUrl = url; | ||
request.headers = getHeadersToSend(requestHeaders); | ||
} | ||
const response = await fetch(requestUrl, request); | ||
const data = await response.text(); | ||
|
||
if (type === "xml") { | ||
return new DOMParser().parseFromString(data, "text/html"); | ||
} else { | ||
if (!data || !data.length > 0) return undefined; | ||
let response = await fetch(requestUrl, request); | ||
if (response.ok) { | ||
const data = await response.text(); | ||
|
||
if (type === "xml") { | ||
return new DOMParser().parseFromString(data, "text/html"); | ||
} else { | ||
if (!data || !data.length > 0) return "null"; //undefined; | ||
|
||
|
||
const dataResponse = JSON.parse(data); | ||
if (!dataResponse.headers) { | ||
dataResponse.headers = getHeadersFromResponse(expectedResponseHeaders, response); | ||
const dataResponse = JSON.parse(data); | ||
if (!dataResponse.headers) { | ||
dataResponse.headers = getHeadersFromResponse(expectedResponseHeaders, response); | ||
} | ||
return dataResponse; | ||
} | ||
return dataResponse; | ||
} else { | ||
throw new Error(`Response status: ${response.status}`); | ||
} | ||
|
||
} | ||
|
||
/** | ||
|
Uh oh!
There was an error while loading. Please reload this page.