RequestHook.onResponse Method

Handles the response after it is received.

class TemplateRequestHook extends RequestHook {
    async onResponse (event) {
        // ...
    }
}

The onResponse method’s event object exposes the following properties:

Property Type Description
event.statusCode Number The response status code.
event.headers Object The response headers in a property-value form.
event.body Buffer The response body.

Important

You cannot change the response body or its status code inside a RequestHook.onResponse() call.

Refer to Change or Delete Response Headers for instructions on how to change or delete response headers.

async onResponse (event) {
    if (event.statusCode === 200)
        console.log(event.headers['Content-Type']);
}