Get HTTP response code on non-2xx apiFetch request

By default, apiFetch will parse the response for you automatically. You can get the raw response object by setting parse to false in the apiFetch option, e.g.:

const handleClick = async () => {
    try {
        const result = await apiFetch( {
            path: '/your/path',
            parse: false,
        } );
        console.log( result ) // you will see ok status (e.g. 200) in here.
    } catch ( error ) {
        console.log( error ); // you will see error status (e.g. 404 or 500) in here.
    }
};

More info: apiFetch’s parse option

Relevant code for parsing the response: see utils/response.js in apiFetch