multiversx / mx-sdk-js-network-providers

Network Provider (API, Gateway) components (compatible with sdk-js).
Other
6 stars 6 forks source link

return errorData.message if exists first #33

Closed juliancwirko closed 1 year ago

juliancwirko commented 1 year ago

Where the errorData.message exists, it will be better to return it first and then errorData.error as a fallback.

Example:

  1. When I do POST using the network provider and underlying doPost to transactions endpoint, I can get:
    {
    "data": {
        "statusCode": 400,
        "message": "transaction generation failed: account not found for address erd1xu09ry2my6r7err6cnjqusrqxa593dxaw3s2pf6ak9vr2f6h685qv4qckw and shard 0, err: account was not found at block: nonce = 54103, hash = 0d67b2bec287109f9e288ddbb2397b73edbc4279b7cbe6d7b763a1ee336cc156, rootHash = 3633f2a9f09f70b6d65d74b33dfb32b0d43df7825561a2ee5936da3d301f379b",
        "error": "Bad Request"
    },
    "status": 400,
    "statusText": "",
    "headers": {
        "content-length": "390",
        "content-type": "application/json; charset=utf-8"
    },
    "config": {
        "transitional": {
            "silentJSONParsing": true,
            "forcedJSONParsing": true,
            "clarifyTimeoutError": false
        },
        "transformRequest": [
            null
        ],
        "transformResponse": [
            null
        ],
        "timeout": 10000,
        "xsrfCookieName": "XSRF-TOKEN",
        "xsrfHeaderName": "X-XSRF-TOKEN",
        "maxContentLength": -1,
        "maxBodyLength": -1,
        "headers": {
            "Accept": "application/json, text/plain, */*",
            "Content-Type": "application/json"
        },
        "method": "post",
        "url": "https://testnet-api.elrond.com/transactions",
        "data": "{\"nonce\":0,\"value\":\"10000000000000000\",\"receiver\":\"erd1qqqqqqqqqqqqqpgqsry4t8prwfqyakelr427k6l7yqff5nzhgtksenwfzq\",\"sender\":\"erd1xu09ry2my6r7err6cnjqusrqxa593dxaw3s2pf6ak9vr2f6h685qv4qckw\",\"gasPrice\":1000000000,\"gasLimit\":13000000,\"data\":\"bWludEAwMQ==\",\"chainID\":\"T\",\"version\":1,\"signature\":\"4130f9b366521a28ec26c4e58b6aac11e835d5c8a06bc8cba19577cfbefa8cede5d1f71eec5f79d4ca2398b108bae4a7c8b51fbbff9ca829b87845e689e81608\"}"
    },
    "request": {}
    }

    So in the current state, instead of getting a proper, well-formatted message, I will get only a Bad request that doesn't tell much.

juliancwirko commented 1 year ago

@andreibancioiu any feedback on this one? It prevents proper error handling when using the lib as is.

andreibancioiu commented 1 year ago

We require all commits to be signed - perhaps the public key isn't configured in your GitHub account?

PR re-did here: https://github.com/multiversx/mx-sdk-js-network-providers/pull/37

juliancwirko commented 1 year ago

Hi, I've changed the laptop and removed the old GPG key. Sorry. So I'll track the #37 thanks

andreibancioiu commented 1 year ago

We've released the fix in v1.3.0.

Thank you :pray: