-
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 #38 from smartsheet/revert-36-personal/mmeyerink/u…
…pdate-http-request-library Revert "remove request in favor of axios"
- Loading branch information
Showing
10 changed files
with
176 additions
and
282 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,30 +1,33 @@ | ||
var Promise = require("bluebird"); | ||
|
||
module.exports = (response) => { | ||
module.exports = (response, body) => { | ||
var outResponse = { | ||
statusCode: response.status, | ||
statusCode: response.statusCode, | ||
headers: response.headers, | ||
body: response.data | ||
body: body | ||
}; | ||
|
||
if (response.status != 200) { | ||
if (response.statusCode != 200) { | ||
var errorResponse = outResponse; | ||
if (/\bapplication\/json\b/.test(response.headers['content-type'])) { | ||
errorResponse.errorCode = response.data.errorCode; | ||
errorResponse.message = response.data.message; | ||
errorResponse.refId = response.data.refId; | ||
var responseBody = JSON.parse(body); | ||
errorResponse.errorCode = responseBody.errorCode; | ||
errorResponse.message = responseBody.message; | ||
errorResponse.refId = responseBody.refId; | ||
|
||
if (response.data.detail !== undefined) { | ||
errorResponse.detail = response.data.detail; | ||
if (responseBody.detail !== undefined) { | ||
errorResponse.detail = responseBody.detail; | ||
} | ||
} else { | ||
errorResponse.message = response.data; | ||
errorResponse.message = body; | ||
} | ||
|
||
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.