export class ResponseError extends Error { constructor(message) { super(message); this.name = "ResponseError"; } } export class NetworkError extends Error { constructor(message) { super(message); this.name = "NetworkError"; } } function getCookie(cname) { let name = cname + "="; let decodedCookie = decodeURIComponent(document.cookie); let ca = decodedCookie.split(";"); for(let i = 0; i { if (!response.ok) { throw new ResponseError(`recieved response status code ${response.status}`); } return response; }) .catch((error) => { if (error instanceof ResponseError) { throw error; } throw new NetworkError(error); }); let data = await response.json(); return data; }