-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add unit tests for utils. refactoring and fixing issues with as…
…ync on funcitons in utils folder. resolving issue with app missing a package that was included in the sourcecode. refined README
- Loading branch information
1 parent
08cec8e
commit 48f7b3e
Showing
10 changed files
with
269 additions
and
110 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,35 +1,33 @@ | ||
|
||
const wreck = require('@hapi/wreck').defaults({ | ||
timeout: 10000 | ||
}) | ||
|
||
function request (method, url, options, ext = false) { | ||
return wreck[method](url, options) | ||
.then(response => { | ||
const res = response.res | ||
const payload = response.payload | ||
const makeRequest = async (method, url, options, ext = false) => { | ||
try { | ||
const response = await wreck[method](url, options) | ||
const { res, payload } = response | ||
|
||
if (res.statusCode !== 200) { | ||
const err = (payload || new Error('Unknown error')) | ||
throw err | ||
} | ||
if (res.statusCode !== 200) { | ||
const err = payload || new Error('Unknown error') | ||
throw err | ||
} | ||
|
||
return payload | ||
}) | ||
} | ||
function get (url, options, ext = false) { | ||
return request('get', url, options, ext) | ||
return payload | ||
} catch (error) { | ||
throw error | ||
} | ||
} | ||
|
||
function post (url, options) { | ||
return request('post', url, options) | ||
} | ||
function getJson (url, ext = false) { | ||
return get(url, { json: true }, ext) | ||
} | ||
const get = async (url, options, ext = false) => | ||
makeRequest('get', url, options, ext) | ||
|
||
const post = async (url, options) => makeRequest('post', url, options) | ||
|
||
const getJson = async (url, ext = false) => get(url, { json: true }, ext) | ||
|
||
module.exports = { | ||
get, | ||
post, | ||
getJson, | ||
request | ||
makeRequest | ||
} |
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
Oops, something went wrong.