node-steamapi icon indicating copy to clipboard operation
node-steamapi copied to clipboard

Don't Promise.reject causing server error 500. console.error instead

Open fungilation opened this issue 3 years ago • 1 comments

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch [email protected] for the project I'm working on.

Here is the diff that solved my problem:

diff --git a/node_modules/steamapi/src/SteamAPI.js b/node_modules/steamapi/src/SteamAPI.js
index d479a8b..f291dc4 100644
--- a/node_modules/steamapi/src/SteamAPI.js
+++ b/node_modules/steamapi/src/SteamAPI.js
@@ -291,7 +291,7 @@ class SteamAPI {
 	 */
 	getUserBans(id) {
 		const arr = Array.isArray(id);
-		if ((arr && id.some(i => !reID.test(i))) || (!arr && !reID.test(id))) return Promise.reject(new TypeError('Invalid/no id provided'));
+		if ((arr && id.some(i => !reID.test(i))) || (!arr && !reID.test(id))) return console.error('SteamAPI: Invalid/no id provided');
 
 		return this
 			.get(`/ISteamUser/GetPlayerBans/v1?steamids=${id}`)
@@ -299,7 +299,7 @@ class SteamAPI {
 				? arr
 					? json.players.map(player => new PlayerBans(player))
 					: new PlayerBans(json.players[0])
-				: Promise.reject(new Error('No players found'))
+				: console.error('SteamAPI: No players found')
 			);
 	}
 
@@ -351,11 +351,11 @@ class SteamAPI {
 	 * @returns {Promise<Game[]>} Owned games
 	 */
 	getUserOwnedGames(id) {
-		if (!reID.test(id)) return Promise.reject(new TypeError('Invalid/no id provided'));
+		if (!reID.test(id)) return console.error('SteamAPI: Invalid/no id provided');
 
 		return this
 			.get(`/IPlayerService/GetOwnedGames/v1?steamid=${id}&include_appinfo=1`)
-			.then(json => json.response.games ? json.response.games.map(game => new Game(game)) : Promise.reject(new Error('No games found')));
+			.then(json => json.response.games ? json.response.games.map(game => new Game(game)) : console.error('SteamAPI: No games found'));
 	}
 
 	/**

This issue body was partially generated by patch-package.

fungilation avatar Mar 14 '22 18:03 fungilation

I'm confused as to how this is a fix. This just makes it harder to handle errors. Perhaps you should make your code handle promise rejections instead?

xDimGG avatar Mar 31 '22 00:03 xDimGG