class Request{ //HTTP response status codes: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status async delete(url){ const deleteResponse = await fetch(url,{ method: "DELETE" })//Continues only after the promise has resolved //Since our method is deleting data //there's no need to return json or text object response from where we make the function call // const responseText = await deleteResponse.json(); // return responseText; //declaration that we're erased the data is enough if(deleteResponse.status === 200){ return "Data Deletion Successful"; //returns a promise } else if (deleteResponse.status >= 400 && deleteResponse.status < 500){ throw new Error("The server could not understand the request due to invalid syntax!"); } else if (deleteResponse.status >= 500 && deleteResponse.status < 600){ throw new Error("Server Error Has Occurred !"); } else{ throw new Error("An Error Occurred! Error type is unknown"); } } } const request = new Request(); //calling delete function request.delete("https://jsonplaceholder.typicode.com/albums/9") .then((result) => console.log(result)) .catch((err) => console.error(err));