Skip to content

Commit

Permalink
fix: check for existence of fetch before using it (#138)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeckwith authored Jun 20, 2019
1 parent 2db0f66 commit 79eb58d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 22 deletions.
17 changes: 14 additions & 3 deletions src/gaxios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,24 @@ import {
GaxiosResponse,
Headers,
} from './common';
import {isBrowser} from './isbrowser';
import {getRetryConfig} from './retry';

// tslint:disable no-any

const URL = isBrowser() ? window.URL : url.URL;
const fetch = isBrowser() ? window.fetch : nodeFetch;
const URL = hasURL() ? window.URL : url.URL;
const fetch = hasFetch() ? window.fetch : nodeFetch;

function hasWindow() {
return typeof window !== 'undefined' && !!window;
}

function hasURL() {
return hasWindow() && !!window.URL;
}

function hasFetch() {
return hasWindow() && !!window.fetch;
}

// tslint:disable-next-line variable-name
let HttpsProxyAgent: any;
Expand Down
19 changes: 0 additions & 19 deletions src/isbrowser.ts

This file was deleted.

0 comments on commit 79eb58d

Please sign in to comment.