diff --git a/spago.dhall b/spago.dhall index 671fd87..1a0b2ff 100644 --- a/spago.dhall +++ b/spago.dhall @@ -3,6 +3,7 @@ [ "aff" , "aff-promise" , "affjax" + , "argonaut" , "argonaut-codecs" , "argonaut-core" , "arrays" diff --git a/src/AjaxUtils.purs b/src/AjaxUtils.purs index f5f56c4..3dc1563 100644 --- a/src/AjaxUtils.purs +++ b/src/AjaxUtils.purs @@ -6,9 +6,9 @@ module AjaxUtils ) where import Prelude hiding (div) -import Affjax (printError) -import Affjax.StatusCode (StatusCode(..)) + import Bootstrap (alertDanger_, btn, floatRight) +import Data.Argonaut (Json, JsonDecodeError) import Data.Argonaut.Core (stringify) import Data.Argonaut.Decode (printJsonDecodeError) import Halogen (RefLabel(RefLabel)) @@ -16,25 +16,26 @@ import Halogen.HTML (ClassName(..), HTML, br_, button, div, p_, text) import Halogen.HTML.Events (onClick) import Halogen.HTML.Properties (class_, classes, ref) import Icons (Icon(..), icon) -import Servant.PureScript (AjaxError, ErrorDescription(..)) +import Servant.PureScript (AjaxError, printAjaxError) data AjaxErrorPaneAction = CloseErrorPane -ajaxErrorPane :: forall p i. AjaxError -> HTML p i +ajaxErrorPane :: forall p i. AjaxError JsonDecodeError Json -> HTML p i ajaxErrorPane error = div [ class_ ajaxErrorClass , ref ajaxErrorRefLabel ] [ alertDanger_ - [ showAjaxError error + [ text $ printAjaxError stringify printJsonDecodeError error , br_ , text "Please try again or contact support for assistance." ] ] -closeableAjaxErrorPane :: forall p. AjaxError -> HTML p AjaxErrorPaneAction +closeableAjaxErrorPane + :: forall p. AjaxError JsonDecodeError Json -> HTML p AjaxErrorPaneAction closeableAjaxErrorPane error = div [ class_ ajaxErrorClass ] @@ -44,7 +45,7 @@ closeableAjaxErrorPane error = , onClick $ const $ CloseErrorPane ] [ icon Close ] - , p_ [ showAjaxError error ] + , p_ [ text $ printAjaxError stringify printJsonDecodeError error ] ] ] @@ -53,24 +54,3 @@ ajaxErrorRefLabel = RefLabel "ajax-error" ajaxErrorClass :: ClassName ajaxErrorClass = ClassName "ajax-error" - -showAjaxError :: forall p i. AjaxError -> HTML p i -showAjaxError = _.description >>> showErrorDescription - -showErrorDescription :: forall p i. ErrorDescription -> HTML p i -showErrorDescription (UnexpectedHTTPStatus { status: StatusCode 404 }) = text - "Data not found." - -showErrorDescription (UnexpectedHTTPStatus { body, status }) = - text - $ "Server error " - <> show status - <> ": " - <> stringify body - -showErrorDescription (DecodingError err) = - text $ "DecodingError: " - <> printJsonDecodeError err - -showErrorDescription (ConnectingError err) = text $ "ConnectionError: " <> - printError err