Skip to content

Commit

Permalink
Return more information than "not logged in" for getConversations (#797)
Browse files Browse the repository at this point in the history
* Return the actual errors when throwing in getConversations

* Check for nonexistent conversation ids

* Add test coverage for nonexistent conversations in getConversations

* Remove nonexistent conversation check

* Remove nonexistent conversation test
  • Loading branch information
Regalijan authored May 3, 2024
1 parent 4930cb8 commit 17f4507
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/chat/getConversations.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ exports.optional = ['jar']
* @example const noblox = require("noblox.js")
* // Login using your cookie
* const conversations = await noblox.getConversations([1, 2, 3])
**/
**/

exports.func = (args) => {
const jar = args.jar
Expand All @@ -28,7 +28,13 @@ exports.func = (args) => {
}
}).then((res) => {
if (res.statusCode !== 200) {
throw new Error('You are not logged in')
const body = JSON.parse(res.body) || {}
if (body.errors && body.errors.length > 0) {
const errors = body.errors.map((e) => {
return e.message
})
throw new Error(`${res.statusCode} ${errors.join(', ')}`)
}
} else {
let response = JSON.parse(res.body)

Expand Down

0 comments on commit 17f4507

Please sign in to comment.