Skip to content

Commit a59b99b

Browse files
committed
Add an error message to getPDF() prompting the user to double-check the record ID
1 parent 27b61b8 commit a59b99b

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

components/quickbooks/quickbooks.app.js

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,22 @@ module.exports = {
7070
return await axios($, requestConfig);
7171
},
7272
async getPDF($, entity, id) {
73-
const companyId = this.companyId();
74-
return await this._makeRequest($, {
75-
path: `company/${companyId}/${entity.toLowerCase()}/${id}/pdf`,
76-
headers: {
77-
"Accept": "application/pdf",
78-
},
79-
responseType: "stream",
80-
});
73+
try {
74+
const companyId = this.companyId();
75+
return await this._makeRequest($, {
76+
path: `company/${companyId}/${entity.toLowerCase()}/${id}/pdf`,
77+
headers: {
78+
"Accept": "application/pdf",
79+
},
80+
responseType: "stream",
81+
});
82+
} catch (ex) {
83+
if (ex.response.data.statusCode === 400) {
84+
throw new Error(`Request failed with status code 400. Double-check that '${id}' is a valid ${entity} record ID.`);
85+
} else {
86+
throw ex;
87+
}
88+
}
8189
},
8290
async getRecordDetails(entityName, id) {
8391
const companyId = this.companyId();

0 commit comments

Comments
 (0)