Skip to content

Commit

Permalink
Fix 'Migration guides' json example
Browse files Browse the repository at this point in the history
  • Loading branch information
szmarczak committed Dec 19, 2018
1 parent 91c0607 commit 0bb9fa6
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions migration-guides.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ const gotInstance = got.extend({
beforeRequest: [
options => {
if (options.json && options.jsonReplacer) {
// #1 solution (faster)
const newBody = {};
for (const [key, value] of Object.entries(options.body)) {
let newValue = value;
Expand All @@ -115,8 +116,6 @@ const gotInstance = got.extend({

newBody[key] = newValue;
}

// #1 solution (faster)
options.body = newBody;

// #2 solution (slower)
Expand All @@ -126,7 +125,7 @@ const gotInstance = got.extend({
],
afterResponse: [
response => {
// TODO in Got: We need to make the `options` public somehow
const options = response.request.gotOptions;
if (options.json && options.jsonReviver) {
response.body = JSON.stringify(JSON.parse(response.body, options.jsonReviver));
}
Expand Down

0 comments on commit 0bb9fa6

Please sign in to comment.