Skip to content

Commit

Permalink
Patch generated js to work with non-json onError
Browse files Browse the repository at this point in the history
  • Loading branch information
googleson78 committed Aug 23, 2020
1 parent cfcca55 commit 88e65b0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 18 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,8 @@ You'll need `libpcre3-dev` + `libmariadbclient-dev` (this is what they're called

This build is in place so that you can easily run a "dev" server afterwards, refer to [Running](#Running).
Building it on your machine might cause a `libc` mismatch between what is in the "deploy" image.

## Modifications to js query functions

Since servant doesn't return json-encoded values for errors (it's plaintext) the js functions need to be modified not to attempt
to parse the error body as json.
21 changes: 3 additions & 18 deletions js/queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,7 @@ const getApiTask = function (backendUrl, onSuccess, onError) {
}
if (res) onSuccess(res)
} else {
try {
res = JSON.parse(xhr.responseText)
} catch (e) {
onError(e)
}
if (res) onError(res)
if (xhr.responseText) onError(xhr.responseText)
}
}
}
Expand All @@ -45,12 +40,7 @@ const postApiTask = function (backendUrl, body, onSuccess, onError) {
}
if (res) onSuccess(res)
} else {
try {
res = JSON.parse(xhr.responseText)
} catch (e) {
onError(e)
}
if (res) onError(res)
if (xhr.responseText) onError(xhr.responseText)
}
}
}
Expand All @@ -75,12 +65,7 @@ const postApiSubmit = function (backendUrl, body, onSuccess, onError) {
}
if (res) onSuccess(res)
} else {
try {
res = JSON.parse(xhr.responseText)
} catch (e) {
onError(e)
}
if (res) onError(res)
if (xhr.responseText) onError(xhr.responseText)
}
}
}
Expand Down

0 comments on commit 88e65b0

Please sign in to comment.