Skip to content
This repository has been archived by the owner on Feb 6, 2024. It is now read-only.

Offline Failure #417

Closed
fny opened this issue Sep 11, 2021 · 7 comments
Closed

Offline Failure #417

fny opened this issue Sep 11, 2021 · 7 comments

Comments

@fny
Copy link
Contributor

fny commented Sep 11, 2021

.data will not be available if the server loses connection to the internet or the MWS servers are down.

.catch((error) => Promise.reject(error.response.data))

A few more cases are required to test for a failure.

function handleError(error) {
    if (error.response) {
        // The request was made and the server responded with a non 200 status
        return ...
    } else if (error.request) {
        // The request was made but no response was received
        return ...
    } else {
        // Something happened in setting up the request that triggered an Error
        return ...
    }
}
@moltar
Copy link
Contributor

moltar commented Sep 11, 2021

@fny Sure, looks about right. Please submit a PR, and we will merge. Thanks!

@fny
Copy link
Contributor Author

fny commented Sep 11, 2021

Do you all have any preference for what the return types should look like?

@moltar
Copy link
Contributor

moltar commented Sep 11, 2021

Do you all have any preference for what the return types should look like?

Not sure what you mean.

Can you please provide a bit more context?

Thanks!

@fny
Copy link
Contributor Author

fny commented Sep 11, 2021

Right now you all have Promise.reject(error.response.data) as the returned value for the cases when the server responds with an error.

In the other two cases what do you want to return?

function handleError(error) {
    if (error.response) {
        // You all have handle this case
        return response.data
    } else if (error.request) {
        // The request was made but no response was received
        // What do we return here?
        return ...
    } else {
        // Something happened in setting up the request that triggered an Error
        // What do were return here?
        return ...
    }
}

@moltar
Copy link
Contributor

moltar commented Sep 13, 2021

I don't think there should be any return if there is an error. Throw a custom error object, if the error is specific and needs handling, or just re-throw the original error.

@moltar
Copy link
Contributor

moltar commented Sep 13, 2021

We already have many error classes defined in: https://github.com/ScaleLeap/amazon-mws-api-sdk/blob/master/src/error.ts

fny added a commit to fny/amazon-mws-api-sdk that referenced this issue Sep 13, 2021
github-actions bot pushed a commit that referenced this issue Sep 14, 2021
## [1.9.56](v1.9.55...v1.9.56) (2021-09-14)

### Bug Fixes

* add checks for offline scenarios [#417](#417) ([#418](#418)) ([b4a8cc9](b4a8cc9))
@moltar
Copy link
Contributor

moltar commented Sep 18, 2021

@fny have you tested this, can this be closed?

@fny fny closed this as completed Oct 10, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants