Skip to content

Commit fd59cda

Browse files
committed
Update got to latest version (Release 5.2.0)
1 parent 6781170 commit fd59cda

File tree

9 files changed

+319
-285
lines changed

9 files changed

+319
-285
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
# [5.2.0] - 2023-04-18
8+
9+
- Update dependency `got` to latest version
10+
711
# [5.1.1] - 2023-04-11
812

913
- Update dependency `serialize-error` to latest version

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ const response = await client.put('/scooters/123',
106106
const response = await client.delete('/scooters/123', { type: 'UNU2' })
107107
```
108108

109-
NOTE: Passing in `options` with a `query` option does overwrite any passed url query arguments:
109+
NOTE: Passing in `options` with a `query` or `searchParams` option does overwrite any passed url query arguments:
110110
```
111111
// This will NOT pass `page`
112112
client.get(`/?page=2`, { query: { type: 'UNU2' }})

lib/components/client.js

+18-7
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,15 @@ class Client {
4242
}
4343

4444
async get(path, options = {}) {
45+
if (options?.query) {
46+
options.searchParams = options.query
47+
delete options.query
48+
}
4549
try {
4650
const response = await got.get(this.makePath(path), {
4751
headers,
4852
retry,
4953
responseType: 'json',
50-
json: true,
5154
...options,
5255
})
5356
return response.body
@@ -63,7 +66,6 @@ class Client {
6366
headers,
6467
retry,
6568
responseType: 'json',
66-
json: true,
6769
})
6870
return response.body
6971
} catch (error) {
@@ -72,13 +74,16 @@ class Client {
7274
}
7375

7476
async post(path, payload, options = {}) {
77+
if (options?.query) {
78+
options.searchParams = options.query
79+
delete options.query
80+
}
7581
try {
7682
const response = await got.post(this.makePath(path), {
7783
headers,
7884
retry,
79-
body: payload,
85+
json: payload,
8086
responseType: 'json',
81-
json: true,
8287
...options,
8388
})
8489

@@ -89,13 +94,16 @@ class Client {
8994
}
9095

9196
async put(path, payload, options = {}) {
97+
if (options?.query) {
98+
options.searchParams = options.query
99+
delete options.query
100+
}
92101
try {
93102
const response = await got.put(this.makePath(path), {
94103
headers,
95104
retry,
96-
body: payload,
105+
json: payload,
97106
responseType: 'json',
98-
json: true,
99107
...options,
100108
})
101109

@@ -106,12 +114,15 @@ class Client {
106114
}
107115

108116
async delete(path, options = {}) {
117+
if (options?.query) {
118+
options.searchParams = options.query
119+
delete options.query
120+
}
109121
try {
110122
const response = await got.delete(this.makePath(path), {
111123
headers,
112124
retry,
113125
responseType: 'json',
114-
json: true,
115126
...options,
116127
})
117128

lib/components/errors.js

+9-12
Original file line numberDiff line numberDiff line change
@@ -56,24 +56,21 @@ const errors = populateConstructorExports(statusCodes)
5656
export const convertToTaubeError = (error) => {
5757
// Detect celebrate errors (joy)
5858
// Ref: https://github.com/arb/celebrate/blob/master/lib/celebrate.js#L180
59-
if (error.body
60-
&& error.body.statusCode == 400
61-
&& error.body.validation) {
62-
return new errors.BadRequest(error.message, error.body.validation)
59+
if (error.response?.body?.statusCode == 400
60+
&& error.response?.body?.validation) {
61+
return new errors.BadRequest(error.message, error.response.body.validation)
6362
}
6463
// Wrap known taube errors in taube error
65-
if (error.body
66-
&& error.body.statusCode
67-
&& errors[error.body.statusCode]) {
68-
return new errors[error.body.statusCode](error.body.message)
64+
if (error.response?.body?.statusCode
65+
&& errors[error.response.body.statusCode]) {
66+
return new errors[error.response.body.statusCode](error.response.body.message)
6967
}
7068

7169
// Wrap known gotjs HTTP errors in taube error
7270
// see https://github.com/sindresorhus/got/blob/29ffb44f6be951e1103bb076dadf2b0e5cbd62f1/source/errors.js#L75
73-
if (error.body
74-
&& error.statusCode
75-
&& errors[error.statusCode]) {
76-
return new errors[error.statusCode](error.message, error.body)
71+
if (error.response?.statusCode
72+
&& errors[error.response.statusCode]) {
73+
return new errors[error.response.statusCode](error.message, error.response.body)
7774
}
7875

7976
// Otherwise we can't deal with this

lib/components/sockend.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ class Namespace {
116116
// Deal with got and other non got errors
117117
.catch((err) => {
118118
debug(err)
119-
if (err && err.statusCode && err.statusMessage) {
120-
return next(new errors[err.statusCode](err.statusMessage))
119+
if (err?.response?.statusCode && err?.response?.statusMessage) {
120+
return next(new errors[err.response.statusCode](err.response.statusMessage))
121121
}
122122
next(new Error('Internal Server Error'))
123123
})

0 commit comments

Comments
 (0)