make server endpoint request errors available on the client
Unanswered
Tonkinese posted this in #help-forum
TonkineseOP
using app router, how can I receive error messages from the backend and parse them the frontend? I would ideally like to pass response.statusText to a usecontext
export async function postFnc({ data }: any) {
try {
const response = await getData('foo');
if (response.status !== 200) {
// send the error to a context for sharing with the UI
console.log(response.statusText);
} else {
// do stuff with the response
}
} catch (error) {
console.log({ error });
}
}2 Replies
TonkineseOP
Ok so how is it done?