From 17f4507785d874476c0db56450d99e7f55110be8 Mon Sep 17 00:00:00 2001 From: Regalijan <72576136+Regalijan@users.noreply.github.com> Date: Fri, 3 May 2024 16:28:17 -0400 Subject: [PATCH] Return more information than "not logged in" for getConversations (#797) * 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 --- lib/chat/getConversations.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/chat/getConversations.js b/lib/chat/getConversations.js index b7614694d..16838706f 100644 --- a/lib/chat/getConversations.js +++ b/lib/chat/getConversations.js @@ -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 @@ -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)