Throw an error from the back-end to the front-end

Hi, so I am doing a fetch request with the post method to the bitdefender api.

The fetch don’t wanted to work until I put it in a .jsw file in the back-end. My problem is that I need to show to the users if there is an error with the request.

I don’t know how to do it cause I can’t use ‘$w’ in the back-end…

Hi Yanis.

I imagine you are still calling the function with the fetch request in your frontend?

This function is a Promise and you can handle errors as you’ll do with any other Promise, using catch()

In case you want to handle different responses from the fetch request (like 200, 404, 500), you can return those values in your backend function, and use either a switch() statement or a conditional statement to handle those different responses in the frontend.

If you can share your code, I might be able to give you more accurate options.