Skip to content
This repository was archived by the owner on Mar 29, 2018. It is now read-only.

Commit e4ada3b

Browse files
author
Daniel Cormier
committed
Better error messaging.
1 parent f4b9c2c commit e4ada3b

File tree

2 files changed

+37
-9
lines changed

2 files changed

+37
-9
lines changed

options.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,31 @@ $(function() {
3030

3131
function load_devices(saved_devices, removeInvalidIds)
3232
{
33+
3334
$("#devices").empty().append(
34-
$("<div>").append("<small>To avoid a neverending loop, Chrome devices are not included.</small>")
35+
$("<div>").append($("<small>").append("Loading devices from PushBullet..."))
3536
);
3637

3738
PushBullet.devices(function(err, res) {
3839
if(err) {
39-
throw err;
40+
if (!err.error) {
41+
msg = err.response;
42+
}
43+
else {
44+
msg = err.error.message;
45+
}
46+
47+
$("#devices").empty().append(
48+
$("<div>").append($("<small>").append("There was a problem. This might help: " + msg))
49+
);
50+
51+
throw err.httpStatus + ' ' + msg;
4052
}
4153
else {
54+
$("#devices").empty().append(
55+
$("<div>").append($("<small>").append("To avoid a neverending loop, Chrome devices are not included."))
56+
);
57+
4258
active_devices = res.devices.filter(filterOutInactiveDevices);
4359
non_chrome_devices = active_devices.filter(filterOutChromeDevices);
4460

@@ -54,7 +70,7 @@ function load_devices(saved_devices, removeInvalidIds)
5470
$("<div>").append(
5571
$("<input>").attr("type", "checkbox").addClass("devices").attr("id",device.iden).val(device.iden).prop('checked', saved_devices.indexOf(device.iden) !== -1)
5672
).append(
57-
$("<label>").attr("for",device.iden).append('<strong>' + device.nickname + '</strong> <small>(' + device.model + ')</small>')
73+
$("<label>").attr("for",device.iden).append($('<strong>').append(device.nickname)).append('&nbsp;').append($('<small>').append('(' + device.model + ')'))
5874
)
5975
);
6076
});

pushbullet.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -246,14 +246,26 @@ var PushBullet = (function() {
246246
};
247247

248248
var handleResponse = function(ajax) {
249-
if(ajax.status !== httpResGood && ajax.status !== httpResNoCont) {
250-
throw new Error(ajax.status + ": " + ajax.response);
251-
}
249+
var response;
250+
252251
try {
253-
return JSON.parse(ajax.response);
254-
} catch(err) {
255-
return ajax.response;
252+
response = JSON.parse(ajax.response);
256253
}
254+
catch (err) {
255+
response = {
256+
response: ajax.response
257+
};
258+
}
259+
260+
if(ajax.status !== httpResGood) {
261+
response.httpStatus = ajax.status;
262+
263+
if (ajax.status !== httpResNoCont) {
264+
throw response;
265+
}
266+
}
267+
268+
return response;
257269
};
258270

259271
return pb;

0 commit comments

Comments
 (0)