From f726390a220b5dec85cc2966be2a1d8fb5d1cfbe Mon Sep 17 00:00:00 2001 From: Dmitrii Kanatnikov Date: Wed, 11 Mar 2020 21:24:01 +0300 Subject: [PATCH] Fix the incorrect example of an `afterResponse` hook (#1115) --- documentation/migration-guides.md | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/documentation/migration-guides.md b/documentation/migration-guides.md index 80aded453..56b441183 100644 --- a/documentation/migration-guides.md +++ b/documentation/migration-guides.md @@ -110,11 +110,18 @@ const gotInstance = got.extend({ } } ], + beforeRequest: [ + options => { + if (options.responseType === 'json' && options.jsonReviver) { + options.responseType = 'text'; + options.customJsonResponse = true; + } + } + ], afterResponse: [ response => { const {options} = response.request; - if (options.jsonReviver && options.responseType === 'json') { - options.responseType = 'text'; + if (options.jsonReviver && options.customJsonResponse) { response.body = JSON.parse(response.body, options.jsonReviver); }