Skip to content
This repository has been archived by the owner on Jan 17, 2023. It is now read-only.

Commit

Permalink
Fix #2305, signal an error when the server isn't available
Browse files Browse the repository at this point in the history
req.onerror is needed to catch connection denied (as opposed to a non-200 request error)
  • Loading branch information
ianb committed Mar 17, 2017
1 parent 3b022ce commit dd75b42
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 6 additions & 0 deletions addon/webextension/background/auth.js
Expand Up @@ -86,6 +86,12 @@ window.auth = (function () {
resolve();
}
});
req.onerror = catcher.watchFunction(() => {
let exc = new Error("Connection failed");
exc.url = loginUrl;
exc.popupMessage = "CONNECTION_ERROR";
reject(exc);
});
req.setRequestHeader("content-type", "application/x-www-form-urlencoded");
req.send(uriEncode({
deviceId: registrationInfo.deviceId,
Expand Down
8 changes: 5 additions & 3 deletions addon/webextension/background/takeshot.js
Expand Up @@ -5,7 +5,7 @@ window.takeshot = (function () {
const Shot = shot.AbstractShot;
const { sendEvent } = analytics;

communication.register("takeShot", (sender, options) => {
communication.register("takeShot", catcher.watchFunction((sender, options) => {
let { captureType, captureText, scroll, selectedPos, shotId, shot } = options;
shot = new Shot(main.getBackend(), shotId, shot);
let capturePromise = Promise.resolve();
Expand Down Expand Up @@ -48,7 +48,7 @@ window.takeshot = (function () {
}).then(() => {
return shot.viewUrl;
}));
});
}));

communication.register("screenshotPage", (sender, selectedPos, scroll) => {
return screenshotPage(selectedPos, scroll);
Expand Down Expand Up @@ -106,7 +106,9 @@ window.takeshot = (function () {
}).then((resp) => {
if (! resp.ok) {
sendEvent("upload-failed", `status-${resp.status}`);
throw new Error("Error: response failed");
let exc = new Error(`Response failed with status ${resp.status}`);
exc.popupMessage = "REQUEST_ERROR";
throw exc;
} else {
sendEvent("upload", "success");
}
Expand Down

0 comments on commit dd75b42

Please sign in to comment.