Skip to content
This repository has been archived by the owner on May 19, 2021. It is now read-only.

Commit

Permalink
[fix] set correct json http get output
Browse files Browse the repository at this point in the history
  • Loading branch information
cedoor committed Dec 8, 2019
1 parent 91fe11e commit 586c104
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 9 additions & 8 deletions src/http/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,20 @@
export function get (url, body) {
return new Promise(function (resolve, reject) {
const http = new window.XMLHttpRequest()
const json = function (string) {
try {
return JSON.parse(string)
} catch (error) {
return string
}
}

http.onreadystatechange = function () {
if (http.readyState === 4) {
if (http.status === 200) {
resolve(http.responseText)
resolve(json(http.responseText))
} else {
try {
const json = JSON.parse(http.responseText)

reject(json)
} catch (error) {
reject(http.responseText)
}
reject(json(http.responseText))
}
}
}
Expand Down

0 comments on commit 586c104

Please sign in to comment.