Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read error message as a string from error object on Node.js

For example I just got this error:

{ Error: There was an error sending your trade offer. We were unable to contact the game's item server. The game's item server may be down or Steam may be experiencing temporary connectivity issues. Please try again later.
    at Object.exports.makeAnError (C:\Some\Boring\Route\node_modules\steam-tradeoffer-manager\lib\helpers.js:17:12)
    at SteamCommunity.manager._community.httpRequestPost...

How do I get just the "There was an error sending your trade offer..." part so I can later send it back to the client?

like image 1000
Petras Vilkelis Avatar asked Nov 05 '17 15:11

Petras Vilkelis


2 Answers

It’s in the message property.

let error = new Error('example');
console.log(error.message);

See also the string representation of errors per ECMAScript.

like image 187
Ry- Avatar answered Oct 04 '22 07:10

Ry-


My err.message is null. I used err.toString() It's saved my ass.

like image 26
taynguyen Avatar answered Oct 04 '22 06:10

taynguyen