Get HTTP response code on non-2xx apiFetch request

I’m using WordPress’ apiFetch library to make requests (in WordPress admin dashboard) to my WordPress REST endpoints. It looks like apiFetch will throw an error if the response is a non-2xx code, using the JSON body of the response as the error. However, it does not appear to be inserting the HTTP code anywhere in that error.

This is necessary since it allows me to differentiate between a "normal" error (like 404 if the resource asked for does not exist) and an "unexpected" error (like a 500 internal server error).

WordPress Development Asked by Nicholas Harris on January 1, 2021

0 Answers

Add your own answers!

Related Questions

add shortcode support in customizer

1  Asked on November 16, 2021 by maheshwaghmare


How to allow duplicate comments?

1  Asked on November 14, 2021 by lumi


Open the attachment details modal

1  Asked on November 11, 2021 by syntacular


custom post type category count shortcode

2  Asked on November 11, 2021 by northtime


How to add classes to post_class?

2  Asked on November 11, 2021 by antonino-lattene


How to do string attachment with wp_mail

3  Asked on November 11, 2021 by nicautre


WP REST API not retrieving all categories

1  Asked on November 11, 2021 by abhivemp


jQuery UI Accordion loading very slow

0  Asked on November 11, 2021 by bluedimensional


Adding a WordPress Admin Dashboard to my local wordpress site

0  Asked on November 11, 2021 by stuart-kushner


How to break meta values into different items and avoid duplicates?

1  Asked on November 11, 2021 by artist-learning-to-code


Ask a Question

Get help from others!

© 2022 All rights reserved.