aboutsummaryrefslogtreecommitdiff
path: root/src/client/Network.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/Network.ts')
-rw-r--r--src/client/Network.ts19
1 files changed, 11 insertions, 8 deletions
diff --git a/src/client/Network.ts b/src/client/Network.ts
index 9afdc844f..a2ecf1bea 100644
--- a/src/client/Network.ts
+++ b/src/client/Network.ts
@@ -1,5 +1,4 @@
import formidable from 'formidable';
-import * as requestPromise from 'request-promise';
import { ClientUtils } from '../ClientUtils';
import { Utils } from '../Utils';
import { Upload } from '../server/SharedMediaTypes';
@@ -15,14 +14,18 @@ export namespace Networking {
return (await fetch(relativeRoute)).text();
}
- export async function PostToServer(relativeRoute: string, body?: unknown) {
- const options = {
- uri: ClientUtils.prepend(relativeRoute),
+ export function PostToServer(relativeRoute: string, body?: unknown) {
+ return fetch(ClientUtils.prepend(relativeRoute), {
method: 'POST',
- body,
- json: true,
- };
- return requestPromise.post(options);
+ headers: {
+ 'Content-Type': 'application/json',
+ },
+ body: body ? JSON.stringify(body) : undefined,
+ }).then(async response => {
+ if (response.ok) return response.json() as object;
+
+ return await response.text().then(text => ({ error: '' + response.status + ':' + response.statusText + '-' + text }));
+ });
}
/**