Skip to content

networkError method should define a request attribute in mocked error response #168

@tiagobnobrega

Description

@tiagobnobrega

When calling networkError, the error returned by the lib should define a request attribute. This is how axios works. It's important because error handling rely on the error.response check. Such as:

.catch((error) => {
        // Error
        if (error.response) {
            // The request was made and the server responded with a status code
            // that falls out of the range of 2xx
            // console.log(error.response.data);
            // console.log(error.response.status);
            // console.log(error.response.headers);
        } else if (error.request) {   //    <--------- THIS CHECK
            // The request was made but no response was received
            // `error.request` is an instance of XMLHttpRequest in the browser and an instance of
            // http.ClientRequest in node.js
            console.log(error.request);
        } else {
            // Something happened in setting up the request that triggered an Error
            console.log('Error', error.message);
        }
        console.log(error.config);
    });

I've managed to workaround this by replying [0,'Network Error']. But, I guess it's not the ideal solution.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions