ScaleLeap / amazon-mws-api-sdk

A fully typed TypeScript and Node.js Amazon MWS API Unofficial SDK
https://npm.im/@scaleleap/amazon-mws-api-sdk
MIT License
20 stars 12 forks source link

Offline Failure #417

Closed fny closed 2 years ago

fny commented 3 years ago

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

https://github.com/ScaleLeap/amazon-mws-api-sdk/blob/7ec26308606b7f48dc1dc089177a2509da4281ef/src/http.ts#L318

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 commented 3 years ago

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

fny commented 3 years ago

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

moltar commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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

moltar commented 3 years ago

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