Skip to content

Commit ec85a7a

Browse files
committed
add try/catch blocks
1 parent cdc1a00 commit ec85a7a

2 files changed

Lines changed: 41 additions & 28 deletions

File tree

src/common/rollbar-api.js

Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -21,44 +21,57 @@ class RollbarAPI {
2121

2222
async deploy(request, deployId) {
2323
let resp;
24-
if(deployId) {
25-
output.verbose('', 'Update to an existing deploy with deploy_id: ' + deployId);
26-
resp = await this.axios.patch('/deploy/' + deployId, request);
27-
} else {
28-
output.verbose('','deploy_id not present so likely a new deploy');
29-
resp = await this.axios.post('/deploy', request);
30-
}
24+
try {
25+
if(deployId) {
26+
output.verbose('', 'Update to an existing deploy with deploy_id: ' + deployId);
27+
resp = await this.axios.patch('/deploy/' + deployId, request);
28+
} else {
29+
output.verbose('','deploy_id not present so likely a new deploy');
30+
resp = await this.axios.post('/deploy', request);
31+
}
3132

32-
// Output deploy-id
33-
if (resp.status === 200) {
34-
output.success('', resp.data.data);
33+
// Output deploy-id
34+
if (resp.status === 200) {
35+
output.success('', resp.data.data);
36+
}
37+
return this.processResponse(resp);
38+
} catch (error) {
39+
output.verbose('', 'axios threw error:', error);
40+
return this.processResponse(error.response || { data: error.message, status: error.status || 500, statusText: error.statusText || 'Axios Error' });
3541
}
36-
return this.processResponse(resp);
3742
}
3843

3944
async sigendURLsourcemaps(request) {
40-
41-
const resp = await this.axios.post(
42-
'/signed_url/sourcemap_bundle', { version: request.version , prefix_url: request.baseUrl}
43-
);
44-
return this.processSignedURLResponse(resp);
45+
try {
46+
const resp = await this.axios.post(
47+
'/signed_url/sourcemap_bundle', { version: request.version , prefix_url: request.baseUrl}
48+
);
49+
return this.processSignedURLResponse(resp);
50+
} catch (error) {
51+
output.verbose('', 'axios threw error:', error);
52+
return this.processSignedURLResponse(error.response || { data: error.message, status: error.status || 500, statusText: error.statusText || 'Axios Error' });
53+
}
4554
}
4655

4756
async sourcemaps(request) {
4857
output.verbose('', 'minified_url: ' + request.minified_url);
4958

5059
const form = this.convertRequestToForm(request);
51-
const resp = await this.axios.post(
52-
'/sourcemap',
53-
form.getBuffer(), // use buffer to prevent unwanted string escaping.
54-
{ headers: {
55-
// axios needs some help with headers for form data.
56-
'Content-Type': `multipart/form-data; boundary=${form.getBoundary()}`,
57-
'Content-Length': form.getLengthSync()
58-
}}
59-
);
60-
61-
return this.processResponse(resp);
60+
try {
61+
const resp = await this.axios.post(
62+
'/sourcemap',
63+
form.getBuffer(), // use buffer to prevent unwanted string escaping.
64+
{ headers: {
65+
// axios needs some help with headers for form data.
66+
'Content-Type': `multipart/form-data; boundary=${form.getBoundary()}`,
67+
'Content-Length': form.getLengthSync()
68+
}}
69+
);
70+
return this.processResponse(resp);
71+
} catch (error) {
72+
output.verbose('', 'axios threw error:', error);
73+
return this.processResponse(error.response || { data: error.message, status: error.status || 500, statusText: error.statusText || 'Axios Error' });
74+
}
6275
}
6376

6477
convertRequestToForm(request) {

test/sourcemaps/scanner.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ describe('.scan()', function() {
139139
await scanner.scan();
140140
const files = scanner.mappedFiles();
141141

142-
expect(files[0].errors[0].error).to.have.string('Error parsing map file: Unexpected token $ in JSON at position 24');
142+
expect(files[0].errors[0].error).to.have.string('Error parsing map file:');
143143
expect(files[1].errors[0].error).to.have.string('Error parsing map file: "sources" is a required argument');
144144
});
145145
});

0 commit comments

Comments
 (0)