Skip to content

Commit

Permalink
modify callback data format
Browse files Browse the repository at this point in the history
  • Loading branch information
nondanee committed Oct 4, 2018
1 parent afd45f7 commit ee0c66d
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions util/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ function createRequest(method, url, data, options){
answer.cookie = (res.headers['set-cookie'] || []).map(x => x.replace(/\s*Domain=[^(;|$)]+;*/, ''))
try{
answer.body = JSON.parse(body)
answer.code = answer.body.code || res.statusCode
answer.status = answer.body.code || res.statusCode
}
catch(e){
answer.body = body
answer.code = res.statusCode
answer.status = res.statusCode
}
answer.code = (answer.code < 100 || answer.code > 600) ? 400 : answer.code
if(answer.code == 200)
answer.status = (100 < answer.status && answer.status < 600) ? answer.status : 400
if(answer.status == 200)
resolve(answer)
else
reject(answer)
Expand Down

0 comments on commit ee0c66d

Please sign in to comment.