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

Wrong error catching method #17

Open
AKJee opened this issue Oct 21, 2020 · 0 comments
Open

Wrong error catching method #17

AKJee opened this issue Oct 21, 2020 · 0 comments
Assignees
Labels

Comments

@AKJee
Copy link

AKJee commented Oct 21, 2020

When doing getTransactionInfo( tId ) - getting unhandled rejection:

UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'data' of undefined
    at get (path\node_modules\node-qiwi-api\lib\asyncApi.js:724:34)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async init (path\index.js:101:13)

Which goes from this fn:

async function get(options) {
        options.headers = headers;
        try {
            var result = await axios.get(options.url, options);
            console.log(result)
            if (result.data.errorCode != undefined)
                throw result.data;

            return result.data;
        }
        catch (error) {
            throw error.response.data;
        }
    }

However if we check error object getting into catch part - it's completely normal response, with fields:

errorCode: 0,
error: null

So the error in comparing 0 with undefined, getting true here, then throwing error.
Line 718
The fix would be like this:

if (result.data.errorCode) {
    //
}

When it's 0 (false) it won't trigger if.
Any other err code will.

or

if (result.data.error != null) {
    //
}

Same error check method is used in lines
736
754
771
788

Also comparisons like this
error.message != undefined

on lines
703
677

May also cause problem at some point ( or at least it's senseless, because of the same reason described above )

Despite I didn't get any missthrows on these lines by now,
I recommend you to look into them more closely and probably change the same way.

@AKJee AKJee changed the title Wrong error response catching Wrong error catching method Oct 21, 2020
@nazarovsa nazarovsa self-assigned this Oct 25, 2020
@nazarovsa nazarovsa added the bug label Oct 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants