mirror of
https://github.com/usebruno/bruno.git
synced 2026-06-26 06:05:45 +00:00
vm2 returns a recursive Proxy for accessing the return value which cannot be serialized for IPC using `structuredClone`. Co-authored-by: ramki-bruno <ramki@usebruno.com>
57 lines
1.2 KiB
JavaScript
57 lines
1.2 KiB
JavaScript
const { get } = require('@usebruno/query');
|
|
const _ = require('lodash');
|
|
|
|
class BrunoResponse {
|
|
constructor(res) {
|
|
this.res = res;
|
|
this.status = res ? res.status : null;
|
|
this.statusText = res ? res.statusText : null;
|
|
this.headers = res ? res.headers : null;
|
|
this.body = res ? res.data : null;
|
|
this.responseTime = res ? res.responseTime : null;
|
|
|
|
// Make the instance callable
|
|
const callable = (...args) => get(this.body, ...args);
|
|
Object.setPrototypeOf(callable, this.constructor.prototype);
|
|
Object.assign(callable, this);
|
|
|
|
return callable;
|
|
}
|
|
|
|
getStatus() {
|
|
return this.res ? this.res.status : null;
|
|
}
|
|
|
|
getStatusText() {
|
|
return this.res ? this.res.statusText : null;
|
|
}
|
|
|
|
getHeader(name) {
|
|
return this.res && this.res.headers ? this.res.headers[name] : null;
|
|
}
|
|
|
|
getHeaders() {
|
|
return this.res ? this.res.headers : null;
|
|
}
|
|
|
|
getBody() {
|
|
return this.res ? this.res.data : null;
|
|
}
|
|
|
|
getResponseTime() {
|
|
return this.res ? this.res.responseTime : null;
|
|
}
|
|
|
|
setBody(data) {
|
|
if (!this.res) {
|
|
return;
|
|
}
|
|
|
|
const clonedData = _.cloneDeep(data);
|
|
this.res.data = clonedData;
|
|
this.body = clonedData;
|
|
}
|
|
}
|
|
|
|
module.exports = BrunoResponse;
|