Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

For http requests, return the original response to the caller, not just 400 #169

Open
KrishnaPG opened this issue Apr 27, 2018 · 1 comment

Comments

@KrishnaPG
Copy link

KrishnaPG commented Apr 27, 2018

Currently the calls to requests, such as postTransactionCommit(createTranfer), when error happens, the driver returns an error that just includes blanket 400 response, which is not useful.

image

In many cases, the server, even though it returns a status code of 400, it also returns a valid response body that will have much more meaningful information to the caller, which is not being supplied to the caller.
image

Instead of returning blanket 400 to the caller, return the original response also to the caller so that they can either log it or display it to the user.

Expected: the values sent to the promise catch handler should include detailed server response, and not just explanation of 400

      conn.postTransactionCommit(createTranfer)
        .then(res => {
            //...
        })
        .catch(err => {
           // Here the err should somehow include the original response from the server.
           // Currently it just says 400 and explanation of 400, which is practically useless
        })
@KrishnaPG KrishnaPG changed the title For http requests requests, return the original response to the caller, not just 400 For http requests, return the original response to the caller, not just 400 Apr 27, 2018
@KrishnaPG
Copy link
Author

The code at https://github.com/bigchaindb/js-bigchaindb-driver/blob/master/src/baseRequest.js#L47 creates a new error object. Instead it should either throw the existing object directly, or add it to the throwing object as below:

function handleResponse(res) {
    if (!(res && res.ok)) {
        throw res; //<-- throw the response object as is. Callers know how to handle fetch errors
    }
    return res
}

or, else:

function handleResponse(res) {
    if (!(res && res.ok)) {
        const errorObject = {
            message: 'HTTP Error: Requested page not reachable',
            status: `${res.status} ${res.statusText}`,
            requestURI: res.url, 
            response: res   //<--- add the original error response here
        }
        throw errorObject
    }
    return res
}

This is really biting hard in the development, since we are almost blind as to why the server is not accepting the post transaction, and we have to manually check the post body externally every time there is a failure, which is very tedious.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants