Skip to content

Commit 740d3f9

Browse files
authored
Merge pull request #24 from truqu/feature/error.name
add getter for error's name when available
2 parents c50c83b + 0a1cd5e commit 740d3f9

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/Control/Monad/Eff/Exception.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ exports.message = function (e) {
1212
return e.message;
1313
};
1414

15+
exports.name = function (e) {
16+
return e.name || "Error";
17+
};
18+
1519
exports.stackImpl = function (just) {
1620
return function (nothing) {
1721
return function (e) {

src/Control/Monad/Eff/Exception.purs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ module Control.Monad.Eff.Exception
66
, Error
77
, error
88
, message
9+
, name
910
, stack
1011
, throwException
1112
, catchException
@@ -37,6 +38,9 @@ foreign import error :: String -> Error
3738
-- | Get the error message from a JavaScript error
3839
foreign import message :: Error -> String
3940

41+
-- | Get the error name when defined, or fallback to 'Error'
42+
foreign import name :: Error -> String
43+
4044
-- | Get the stack trace from a JavaScript error
4145
stack :: Error -> Maybe String
4246
stack = stackImpl Just Nothing

0 commit comments

Comments
 (0)