Status code handling before parsing

This commit is contained in:
Tilman Kamp 2018-10-10 13:53:45 +02:00
Родитель 7c79bd5442
Коммит 5592b2e94f
1 изменённых файлов: 5 добавлений и 5 удалений

10
lib.js
Просмотреть файл

@ -89,7 +89,7 @@ exports.mount = function(endpoint, mountpoint, options, callback) {
if (retries > 0) {
delete call.request
call.timer = setTimeout(() => {
logDebug('sending (' + retries + 'left)', call.operation)
logDebug('sending (' + retries + ' tries left)', call.operation)
sendRequest(call, retries - 1)
}, 1000)
} else {
@ -103,6 +103,10 @@ exports.mount = function(endpoint, mountpoint, options, callback) {
let chunks = []
res.on('data', chunk => chunks.push(chunk))
res.on('end', () => {
if (res.statusCode != 200) {
logDebug('Status code ' + res.statusCode)
return handleError(-70)
}
let result
try {
result = serializer.fromBuffer(Buffer.concat(chunks))
@ -110,10 +114,6 @@ exports.mount = function(endpoint, mountpoint, options, callback) {
logDebug('Problem parsing response buffer')
return handleError(-70)
}
if (res.statusCode != 200) {
logDebug('Status code ' + res.statusCode)
return handleError(-70)
}
removeCall(call)
call.callback.apply(null, result)
})