Files
the-jailor/wwwroot/core/utils/requester.js
2025-11-09 10:23:23 +01:00

35 lines
1021 B
JavaScript

import {Logger} from "../logging/logger.js";
export class Requester {
static async doGetRequest(url){
return fetch(url)
.then(async response => {
if (!response.ok) {
throw new Error(`HTTP ${response.status} ${response.statusText} : ${await response.text()}`);
}
return response.json();
})
.then(data => {
return data;
})
.catch(async error => {
await Logger.error(`Failed to fetch`, error);
throw error;
});
}
static async doPostRequest(url, headers, body){
return await fetch(url,{
method: 'POST',
headers: headers,
body: body
})
.then(response => response.json())
.then(data => {
return data;
})
.catch(error => {
Logger.error(`Unable to fetch`, error);
});
}
}