Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/api/reports/reports.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ export default class Reports {
*
* @memberof Reports
* @param {string} id The ID of the report that the file belongs to.
* @param {Object} fileId The ID of the file to retrieve.
* @return {Promise<Object>} A promise to the Reports response.
* @param {string} fileId The ID of the file to retrieve.
* @return {Promise<Buffer>} A promise to the content of the file.
* @throws {ValueError} If id or fileId is undefined, null, empty, "." or "..", or contains "/",
* "\", an ASCII control character or an unpaired surrogate.
*/
Expand All @@ -73,7 +73,8 @@ export default class Reports {
const response = await get(
this.config.httpClient,
`${this.config.host}/${REPORTS_PATH}/${encodePathSegment(id, 'id')}/${FILES_PATH}/${encodePathSegment(fileId, 'fileId')}`,
{ ...this.config, csv: true },
// The file is served from another location: one 302 to it is followed (see http.js downloadFile).
{ ...this.config, csv: true, fileDownload: true },
this.config.sk
);
return await response.csv;
Expand Down
12 changes: 12 additions & 0 deletions src/services/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,19 @@ export class ValueError extends Error {
}
}

/**
* Map an error thrown by the HTTP layer to the SDK error the caller receives.
*
* @param {*} err An SDK error (returned unchanged), a `{ status, json }` error response or a
* client error.
* @return {Promise<Error>} The SDK error.
* @throws {ValueError} When err is a ValueError.
*/
export const determineError = async (err) => {
// Already an SDK error thrown by the HTTP layer (every one sets http_code): keep its type and body
if (err instanceof Error && Object.hasOwn(err, 'http_code')) {
return err;
}

if (
err instanceof ApiTimeout ||
Expand Down
Loading
Loading