JQXHR Object simply outputs to [object Object]

153 Views Asked by At

I have an API endpoint for registering a user written in Python Flask. I can see on the linux console that Flask is returning a 400 when the password does not have a lower case letter in it and it returns the json data {'error':{'code':{'password_missing_lower_case_letters'}}, which I need to process and return feedback to the use, but I can't access this on the browser and all jq_xhr outputs is [object Object]. I know everything else is working because when I do add a lower case letter, the user is successfully registered. What am I doing wrong that prevents me from reading the returned data on error from the jqxhr object?

$.ajax({
    type: 'POST',
    url: `${g_domain__api}/register_user`,
    data: JSON.stringify(data),
    datatype: 'json',
    contentType: 'application/json; charset=utf-8',
    success: function (data, text_status, jq_xhr) {
        console.log ('I am happy!');
    },
    error: function (jq_xhr, text_status, error_thrown) {
        //I'm getting desperate here and logging everything I can
        console.log(`jq_xhr-> ${jq_xhr}`);
        console.log(`text_status-> ${text_status}`);
        console.log(`error_thrown-> ${error_thrown}`);
    }
});

Browser console output:

jq_xhr-> [object Object]
text_status-> error
error_thrown-> BAD REQUEST
0

There are 0 best solutions below