Skip to content

Commit

Permalink
fix(Headers): headers should be set when request is open
Browse files Browse the repository at this point in the history
  • Loading branch information
lemoustachiste committed Jan 23, 2023
1 parent 8879f16 commit 4ffb4e2
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/services/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ export default async function request (obj: IRequestParameters): Promise<any> {
const XHR = typeof XMLHttpRequest === 'undefined' ? xhrPolyfill : XMLHttpRequest;
const request: XMLHttpRequest = new XHR();

if (obj['bearer-token']) {
request.setRequestHeader('Authorization', `Bearer ${obj['bearer-token']}`);
}

request.onload = () => {
if (request.status >= 200 && request.status < 300) {
resolve(request.responseText);
Expand Down Expand Up @@ -56,6 +52,10 @@ export default async function request (obj: IRequestParameters): Promise<any> {

request.open(obj.method || 'GET', url);

if (obj['bearer-token']) {
request.setRequestHeader('Authorization', `Bearer ${obj['bearer-token']}`);
}

if (obj.body) {
request.send(JSON.stringify(obj.body));
} else {
Expand Down

0 comments on commit 4ffb4e2

Please sign in to comment.