Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Get http response status code after response.json()

I would like to get http status code after response.json to use it in my logic later, can I do something with it?

function apiRequest(path, options) {
    fetch("api/" + path, options)
        .then(response => response.json())
        .then(data => {
            let res = {
                code: 200 //I want to put http status code here,
                data: data
            }

            return res;
        })
}

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Try this

function apiRequest(path, options) {
    fetch("api/" + path, options)
        .then(response => Promise.all([Promise.resolve(response.status), response.json()]))
        .then([status, data] => {
            let res = {
                code: status //I want to put http status code here,
                data: data
            }

            return res;
        })
}

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading