TransWikia.com

Get HTTP response code on non-2xx apiFetch request

WordPress Development Asked by Nicholas Harris on January 1, 2021

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).

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP