aboutsummaryrefslogtreecommitdiffstats
path: root/packages/website/ts/utils/fetch_utils.ts
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2018-06-06 17:10:27 +0800
committerFabio Berger <me@fabioberger.com>2018-06-06 17:10:27 +0800
commitcbfed99bc6f9c86dee2dc31cafe401ded0fc9084 (patch)
tree6a1608b6fca9366f6b407e8a2cf746a79b86858b /packages/website/ts/utils/fetch_utils.ts
parent05b9dfbe30c55a67e6d2d63898f52e5fa412fcfb (diff)
parent39570a9663abae56b0220745306386197fae65c1 (diff)
downloaddexon-0x-contracts-cbfed99bc6f9c86dee2dc31cafe401ded0fc9084.tar
dexon-0x-contracts-cbfed99bc6f9c86dee2dc31cafe401ded0fc9084.tar.gz
dexon-0x-contracts-cbfed99bc6f9c86dee2dc31cafe401ded0fc9084.tar.bz2
dexon-0x-contracts-cbfed99bc6f9c86dee2dc31cafe401ded0fc9084.tar.lz
dexon-0x-contracts-cbfed99bc6f9c86dee2dc31cafe401ded0fc9084.tar.xz
dexon-0x-contracts-cbfed99bc6f9c86dee2dc31cafe401ded0fc9084.tar.zst
dexon-0x-contracts-cbfed99bc6f9c86dee2dc31cafe401ded0fc9084.zip
Merge branch 'v2-prototype' into fixes/misc-small-fixes
* v2-prototype: Remove TranslatedText Fix prettier Add back UMD bundles for 0x.js Move portal disclaimer to the account management section Move prices into portal Use stricter check for subscribe input text Make buttons stack on mobile Do not show subscribe form if language is not english Address PR feedback Lint and cleanup Implement subscription form Add styled-components and polished Have basic newsletter subscribe form working
Diffstat (limited to 'packages/website/ts/utils/fetch_utils.ts')
-rw-r--r--packages/website/ts/utils/fetch_utils.ts32
1 files changed, 24 insertions, 8 deletions
diff --git a/packages/website/ts/utils/fetch_utils.ts b/packages/website/ts/utils/fetch_utils.ts
index d2e902db5..513f7e479 100644
--- a/packages/website/ts/utils/fetch_utils.ts
+++ b/packages/website/ts/utils/fetch_utils.ts
@@ -4,22 +4,38 @@ import * as queryString from 'query-string';
import { errorReporter } from 'ts/utils/error_reporter';
+const logErrorIfPresent = (response: Response, requestedURL: string) => {
+ if (response.status !== 200) {
+ const errorText = `Error requesting url: ${requestedURL}, ${response.status}: ${response.statusText}`;
+ logUtils.log(errorText);
+ const error = Error(errorText);
+ // tslint:disable-next-line:no-floating-promises
+ errorReporter.reportAsync(error);
+ throw error;
+ }
+};
+
export const fetchUtils = {
async requestAsync(baseUrl: string, path: string, queryParams?: object): Promise<any> {
const query = queryStringFromQueryParams(queryParams);
const url = `${baseUrl}${path}${query}`;
const response = await fetch(url);
- if (response.status !== 200) {
- const errorText = `Error requesting url: ${url}, ${response.status}: ${response.statusText}`;
- logUtils.log(errorText);
- const error = Error(errorText);
- // tslint:disable-next-line:no-floating-promises
- errorReporter.reportAsync(error);
- throw error;
- }
+ logErrorIfPresent(response, url);
const result = await response.json();
return result;
},
+ async postAsync(baseUrl: string, path: string, body: object): Promise<Response> {
+ const url = `${baseUrl}${path}`;
+ const response = await fetch(url, {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json',
+ },
+ body: JSON.stringify(body),
+ });
+ logErrorIfPresent(response, url);
+ return response;
+ },
};
function queryStringFromQueryParams(queryParams?: object): string {