From 0a1cd5e923adf26d416716806144edfaa66d7f51 Mon Sep 17 00:00:00 2001 From: KtorZ Date: Thu, 20 Jul 2017 11:26:39 +0200 Subject: [PATCH] add getter for error's name when available --- src/Control/Monad/Eff/Exception.js | 4 ++++ src/Control/Monad/Eff/Exception.purs | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/Control/Monad/Eff/Exception.js b/src/Control/Monad/Eff/Exception.js index 554457d..a5aa8c4 100644 --- a/src/Control/Monad/Eff/Exception.js +++ b/src/Control/Monad/Eff/Exception.js @@ -12,6 +12,10 @@ exports.message = function (e) { return e.message; }; +exports.name = function (e) { + return e.name || "Error"; +}; + exports.stackImpl = function (just) { return function (nothing) { return function (e) { diff --git a/src/Control/Monad/Eff/Exception.purs b/src/Control/Monad/Eff/Exception.purs index f0b79c5..2ead062 100644 --- a/src/Control/Monad/Eff/Exception.purs +++ b/src/Control/Monad/Eff/Exception.purs @@ -6,6 +6,7 @@ module Control.Monad.Eff.Exception , Error , error , message + , name , stack , throwException , catchException @@ -37,6 +38,9 @@ foreign import error :: String -> Error -- | Get the error message from a JavaScript error foreign import message :: Error -> String +-- | Get the error name when defined, or fallback to 'Error' +foreign import name :: Error -> String + -- | Get the stack trace from a JavaScript error stack :: Error -> Maybe String stack = stackImpl Just Nothing