mirror of
https://github.com/sasjs/adapter.git
synced 2026-01-06 20:10:05 +00:00
Merge pull request #37 from sasjs/ie-edge-fetch
fix(*): use fetch polyfill in IE, Edge and Firefox <60
This commit is contained in:
13
src/SASjs.ts
13
src/SASjs.ts
@@ -1,6 +1,10 @@
|
|||||||
import "isomorphic-fetch";
|
|
||||||
import * as e6p from "es6-promise";
|
import * as e6p from "es6-promise";
|
||||||
(e6p as any).polyfill();
|
(e6p as any).polyfill();
|
||||||
|
if (isIEorEdgeOrOldFirefox()) {
|
||||||
|
window.fetch = undefined as any; // ensure the polyfill runs
|
||||||
|
}
|
||||||
|
// tslint:disable-next-line
|
||||||
|
require("isomorphic-fetch");
|
||||||
import {
|
import {
|
||||||
convertToCSV,
|
convertToCSV,
|
||||||
compareTimestamps,
|
compareTimestamps,
|
||||||
@@ -27,6 +31,7 @@ import {
|
|||||||
import { SASViyaApiClient } from "./SASViyaApiClient";
|
import { SASViyaApiClient } from "./SASViyaApiClient";
|
||||||
import { SAS9ApiClient } from "./SAS9ApiClient";
|
import { SAS9ApiClient } from "./SAS9ApiClient";
|
||||||
import { FileUploader } from "./FileUploader";
|
import { FileUploader } from "./FileUploader";
|
||||||
|
import { isIEorEdgeOrOldFirefox } from "./utils/isIeOrEdge";
|
||||||
|
|
||||||
const defaultConfig: SASjsConfig = {
|
const defaultConfig: SASjsConfig = {
|
||||||
serverUrl: "",
|
serverUrl: "",
|
||||||
@@ -654,9 +659,11 @@ export default class SASjs {
|
|||||||
try {
|
try {
|
||||||
responseJson = JSON.parse(response!.result);
|
responseJson = JSON.parse(response!.result);
|
||||||
} catch {
|
} catch {
|
||||||
responseJson = JSON.parse(parseWeboutResponse(response!.result));
|
responseJson = JSON.parse(
|
||||||
|
parseWeboutResponse(response!.result)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return responseJson;
|
return responseJson;
|
||||||
})
|
})
|
||||||
.catch(async (e) => {
|
.catch(async (e) => {
|
||||||
|
|||||||
31
src/utils/isIeOrEdge.ts
Normal file
31
src/utils/isIeOrEdge.ts
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
export function isIEorEdgeOrOldFirefox() {
|
||||||
|
const ua = window.navigator.userAgent;
|
||||||
|
|
||||||
|
if (ua.indexOf("Firefox") > 0) {
|
||||||
|
const version = parseInt(
|
||||||
|
ua.substring(ua.lastIndexOf("Firefox/") + 8, ua.length),
|
||||||
|
10
|
||||||
|
);
|
||||||
|
return version <= 60;
|
||||||
|
}
|
||||||
|
|
||||||
|
const msie = ua.indexOf("MSIE ");
|
||||||
|
if (msie > 0) {
|
||||||
|
// IE 10 or older => return version number
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
const trident = ua.indexOf("Trident/");
|
||||||
|
if (trident > 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
const edge = ua.indexOf("Edge/");
|
||||||
|
if (edge > 0) {
|
||||||
|
// Edge (IE 12+) => return version number
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// other browser
|
||||||
|
return false;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user