Initial commit
This commit is contained in:
35
wwwroot/core/utils/requester.js
Normal file
35
wwwroot/core/utils/requester.js
Normal file
@@ -0,0 +1,35 @@
|
||||
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);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user