Skip to content

Preserve server error-data #28

Closed
Closed
@MarcRoemmelt

Description

@MarcRoemmelt

Hi! Thanks for the useful lib. We have been using it for a while and have a small suggestion for an improvement.

Is your feature request related to a problem? Please describe.
The current implementation ignores the error returned by the server, which may contain useful information (e.g. please complete step xyc before downloading this file). Instead it throws a generic new Error(${response.status} ${response.type} ${response.statusText}) for all error status codes.

Describe the solution you'd like
It would be useful to capture the error contained in the request body and use that as the error (if there is one).

Describe alternatives you've considered
Verifying that the download is generally possible/allowed could be implemented via secondary routes instead of relying on the error for feedback. However, that seems like an unnecessary workaround. Errors should be usable in the client.

Additional context

// instead of throwing this error here, throw an error based on the request body
// l. 24
if (!response.ok) {
  throw Error(`${response.status} ${response.type} ${response.statusText}`);
}

// e.g.
// l. 231
.then(resolverWithProgress)
.then((response) => {
    if (response.ok) return response;

    return response.json().then((errorObj) => /* set or throw custom error and handle in error-handler below */);
})
.then((data) => {
    return data.blob();
})

I'm happy to open a PR for this feature if you like! :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions