Skip to content
This repository was archived by the owner on Aug 11, 2021. It is now read-only.

Commit ed0236e

Browse files
watildezkat
authored andcommitted
ping: response all data even an error exists (#149)
PR-URL: #149 Credit: @watilde Reviewed-By: @zkat
1 parent b6069f9 commit ed0236e

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

lib/ping.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,9 @@ function ping (uri, params, cb) {
1111
var auth = params.auth
1212
assert(auth && typeof auth === 'object', 'must pass auth to ping')
1313

14-
this.request(url.resolve(uri, '-/ping?write=true'), { auth: auth }, function (er, fullData) {
15-
if (er) {
16-
cb(er)
17-
} else if (fullData) {
18-
cb(null, fullData)
14+
this.request(url.resolve(uri, '-/ping?write=true'), { auth: auth }, function (er, fullData, data, response) {
15+
if (er || fullData) {
16+
cb(er, fullData, data, response)
1917
} else {
2018
cb(new Error('No data received'))
2119
}

test/ping.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,27 @@ test('ping', function (t) {
7474
t.end()
7575
})
7676
})
77+
78+
test('ping 404', function (t) {
79+
server.expect('GET', '/-/ping?write=true', function (req, res) {
80+
t.equal(req.method, 'GET')
81+
res.statusCode = 404
82+
res.json({
83+
statusCode: 404,
84+
error: 'Not Found'
85+
})
86+
})
87+
88+
client.ping(common.registry, PARAMS, function (error, found, data, res) {
89+
t.same(error.message, 'Not Found : -/ping')
90+
var wanted = {
91+
statusCode: 404,
92+
error: 'Not Found'
93+
}
94+
t.same(found, wanted)
95+
t.same(data, JSON.stringify(wanted))
96+
t.same(res.body.toString(), JSON.stringify(wanted))
97+
server.close()
98+
t.end()
99+
})
100+
})

0 commit comments

Comments
 (0)