mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-23 20:18:00 +01:00
convert request utils to typescript
This commit is contained in:
parent
cccbcd041f
commit
2b4ed32233
1 changed files with 6 additions and 4 deletions
|
@ -1,7 +1,9 @@
|
||||||
// Request Utils
|
// Request Utils
|
||||||
|
|
||||||
export function fetchJson(verb, endpoint, body) {
|
type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH';
|
||||||
const data = {
|
|
||||||
|
export function fetchJson(verb: HttpMethod, endpoint: string, body?: Record<string, unknown>): Promise<Response> {
|
||||||
|
const data: RequestInit = {
|
||||||
method: verb,
|
method: verb,
|
||||||
credentials: 'same-origin',
|
credentials: 'same-origin',
|
||||||
headers: {
|
headers: {
|
||||||
|
@ -19,7 +21,7 @@ export function fetchJson(verb, endpoint, body) {
|
||||||
return fetch(endpoint, data);
|
return fetch(endpoint, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function fetchHtml(endpoint) {
|
export function fetchHtml(endpoint: string): Promise<Response> {
|
||||||
return fetch(endpoint, {
|
return fetch(endpoint, {
|
||||||
credentials: 'same-origin',
|
credentials: 'same-origin',
|
||||||
headers: {
|
headers: {
|
||||||
|
@ -29,7 +31,7 @@ export function fetchHtml(endpoint) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function handleError(response) {
|
export function handleError(response: Response): Response {
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error('Received error from server');
|
throw new Error('Received error from server');
|
||||||
}
|
}
|
Loading…
Reference in a new issue