async function apiRequest(path, options = {}) {
const response = await fetch(`${BASE_URL}${path}`, {
...options,
headers: {
'X-Api-Key': API_KEY,
'Content-Type': 'application/json',
...options.headers
}
});
const data = await response.json();
if (!response.ok) {
throw new UnleeshedError(
data.error.code,
data.error.message,
response.status,
data.error.details
);
}
return data;
}
class UnleeshedError extends Error {
constructor(code, message, status, details = {}) {
super(message);
this.code = code;
this.status = status;
this.details = details;
}
}