browser fixes
This commit is contained in:
parent
af08b2d1fe
commit
3773a4cdff
@ -24,6 +24,7 @@ import {
|
|||||||
HttpRequestOptions,
|
HttpRequestOptions,
|
||||||
HttpResponse,
|
HttpResponse,
|
||||||
Headers,
|
Headers,
|
||||||
|
bytesToString,
|
||||||
} from "taler-wallet-core";
|
} from "taler-wallet-core";
|
||||||
import { TalerErrorCode } from "taler-wallet-core";
|
import { TalerErrorCode } from "taler-wallet-core";
|
||||||
|
|
||||||
@ -78,10 +79,16 @@ export class BrowserHttpLib implements HttpRequestLibrary {
|
|||||||
reject(exc);
|
reject(exc);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
const makeText = async (): Promise<string> => {
|
||||||
|
const td = new TextDecoder();
|
||||||
|
return td.decode(myRequest.response);
|
||||||
|
};
|
||||||
const makeJson = async (): Promise<any> => {
|
const makeJson = async (): Promise<any> => {
|
||||||
let responseJson;
|
let responseJson;
|
||||||
try {
|
try {
|
||||||
responseJson = JSON.parse(myRequest.responseText);
|
const td = new TextDecoder();
|
||||||
|
const responseString = td.decode(myRequest.response);
|
||||||
|
responseJson = JSON.parse(responseString);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw OperationFailedError.fromCode(
|
throw OperationFailedError.fromCode(
|
||||||
TalerErrorCode.WALLET_RECEIVED_MALFORMED_RESPONSE,
|
TalerErrorCode.WALLET_RECEIVED_MALFORMED_RESPONSE,
|
||||||
@ -126,7 +133,7 @@ export class BrowserHttpLib implements HttpRequestLibrary {
|
|||||||
headers: headerMap,
|
headers: headerMap,
|
||||||
requestMethod: method,
|
requestMethod: method,
|
||||||
json: makeJson,
|
json: makeJson,
|
||||||
text: async () => myRequest.responseText,
|
text: makeText,
|
||||||
bytes: async () => myRequest.response,
|
bytes: async () => myRequest.response,
|
||||||
};
|
};
|
||||||
resolve(resp);
|
resolve(resp);
|
||||||
@ -149,7 +156,7 @@ export class BrowserHttpLib implements HttpRequestLibrary {
|
|||||||
): Promise<HttpResponse> {
|
): Promise<HttpResponse> {
|
||||||
return this.fetch(url, {
|
return this.fetch(url, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body,
|
body: JSON.stringify(body),
|
||||||
...opt,
|
...opt,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user