In order to test how the front-end responds to various HTTP status error codes, I want to intentionally return an Error from one of my front-end service methods to simulate an Error from one of the API endpoints. The question is... how to do it in a more detailed manner.
I tried using the new Error()
constructor, but I can see that I just have the option to add a message as argument to the constructor. I would also want to mock a status code, like for example 500
.
The question that was pointed as a potential solution, How do I create a custom Error in JavaScript?, does not solve my problem. In the question and answers it is mentioned that the person wants to simply throw a new error with a name and a message, while I would also want to be able to throw different Error codes.