Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async respond(response) {
const { statusCode, headers, body } = response || {};
assert(
'Cannot respond to a request that already has a response.',
!this.didRespond
);
// Timestamp the response
this.response.timestamp = timestamp();
// Set the status code
this.response.status(statusCode);
// Se the headers
this.response.setHeaders(headers);
// Set the body without modifying any headers (instead of using .send())
this.response.body = body;
// Trigger the `beforeResponse` event
await this._emit('beforeResponse', this.response);
// End the response so it can no longer be modified
this.response.end();
async setup() {
// Trigger the `request` event
await this._emit('request');
// Setup the response
this.response = new PollyResponse();
this.didRespond = false;
// Setup this request's identifiers, id, and order
await this._identify();
// Timestamp the request
this.timestamp = timestamp();
}