-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from mattmeyerink/personal/mmeyerink/update-ht…
…tp-request-library feat: remove Axios in favor of request
- Loading branch information
Showing
10 changed files
with
399 additions
and
205 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,30 @@ | ||
var Promise = require("bluebird"); | ||
|
||
module.exports = (response, body) => { | ||
module.exports = (response) => { | ||
var outResponse = { | ||
statusCode: response.statusCode, | ||
statusCode: response.status, | ||
headers: response.headers, | ||
body: body | ||
body: response.data | ||
}; | ||
|
||
if (response.statusCode != 200) { | ||
if (response.status != 200) { | ||
var errorResponse = outResponse; | ||
if (/\bapplication\/json\b/.test(response.headers['content-type'])) { | ||
var responseBody = JSON.parse(body); | ||
errorResponse.errorCode = responseBody.errorCode; | ||
errorResponse.message = responseBody.message; | ||
errorResponse.refId = responseBody.refId; | ||
errorResponse.errorCode = response.data.errorCode; | ||
errorResponse.message = response.data.message; | ||
errorResponse.refId = response.data.refId; | ||
|
||
if (responseBody.detail !== undefined) { | ||
errorResponse.detail = responseBody.detail; | ||
if (response.data.detail !== undefined) { | ||
errorResponse.detail = response.data.detail; | ||
} | ||
} else { | ||
errorResponse.message = body; | ||
errorResponse.message = response.data; | ||
} | ||
|
||
return new Promise.reject(errorResponse); | ||
} else if (response.headers['content-type'] === 'application/json;charset=UTF-8') { | ||
outResponse.content = JSON.parse(body); | ||
return outResponse; | ||
} else { | ||
outResponse.content = body; | ||
return outResponse; | ||
} | ||
|
||
outResponse.content = response.data; | ||
|
||
return outResponse; | ||
}; |
Oops, something went wrong.