1
0
mirror of https://github.com/sasjs/adapter.git synced 2026-01-04 11: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:
Krishna Acondy
2020-08-13 21:56:11 +01:00
committed by GitHub
2 changed files with 41 additions and 3 deletions

View File

@@ -1,6 +1,10 @@
import "isomorphic-fetch";
import * as e6p from "es6-promise";
(e6p as any).polyfill();
if (isIEorEdgeOrOldFirefox()) {
window.fetch = undefined as any; // ensure the polyfill runs
}
// tslint:disable-next-line
require("isomorphic-fetch");
import {
convertToCSV,
compareTimestamps,
@@ -27,6 +31,7 @@ import {
import { SASViyaApiClient } from "./SASViyaApiClient";
import { SAS9ApiClient } from "./SAS9ApiClient";
import { FileUploader } from "./FileUploader";
import { isIEorEdgeOrOldFirefox } from "./utils/isIeOrEdge";
const defaultConfig: SASjsConfig = {
serverUrl: "",
@@ -654,9 +659,11 @@ export default class SASjs {
try {
responseJson = JSON.parse(response!.result);
} catch {
responseJson = JSON.parse(parseWeboutResponse(response!.result));
responseJson = JSON.parse(
parseWeboutResponse(response!.result)
);
}
return responseJson;
})
.catch(async (e) => {

31
src/utils/isIeOrEdge.ts Normal file
View 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;
}