@@ -12,7 +12,7 @@ export default class HTTPResponse {
|
||||
let _text, _data;
|
||||
this.status = response.statusCode;
|
||||
this.headers = response.headers || {};
|
||||
this.cookies = this.headers["set-cookie"];
|
||||
this.cookies = this.headers['set-cookie'];
|
||||
|
||||
if (typeof body == 'string') {
|
||||
_text = body;
|
||||
@@ -29,29 +29,33 @@ export default class HTTPResponse {
|
||||
_text = JSON.stringify(_data);
|
||||
}
|
||||
return _text;
|
||||
}
|
||||
};
|
||||
|
||||
const getData = () => {
|
||||
if (!_data) {
|
||||
try {
|
||||
_data = JSON.parse(getText());
|
||||
} catch (e) { /* */ }
|
||||
} catch (e) {
|
||||
/* */
|
||||
}
|
||||
}
|
||||
return _data;
|
||||
}
|
||||
};
|
||||
|
||||
Object.defineProperty(this, 'body', {
|
||||
get: () => { return body }
|
||||
get: () => {
|
||||
return body;
|
||||
},
|
||||
});
|
||||
|
||||
Object.defineProperty(this, 'text', {
|
||||
enumerable: true,
|
||||
get: getText
|
||||
get: getText,
|
||||
});
|
||||
|
||||
Object.defineProperty(this, 'data', {
|
||||
enumerable: true,
|
||||
get: getData
|
||||
get: getData,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user