Commit 8809d506 authored by Allele Dev's avatar Allele Dev

improve JSON instance

parent b782971d
{-# LANGUAGE OverloadedStrings #-}
module API.Errors (
APIError(..),
ViewErrors(..)
) where
import Data.Aeson
import Data.Aeson.Types
import Data.Text
import Data.UUID
......@@ -20,33 +20,36 @@ data APIError
newtype ViewErrors = ViewErrors [APIError]
(.=.) :: Text -> Text -> Pair
k .=. v = k .= v
instance ToJSON APIError where
toJSON (Unknown t) =
object [ "type" .= ("unknown" :: Text)
object [ "type" .=. "unknown"
, "description" .= t
]
toJSON AuthenticationDown =
object [ "type" .= ("authentication_down" :: Text) ]
object [ "type" .=. "authentication_down" ]
toJSON Unauthorized =
object [ "type" .= ("unauthorized" :: Text) ]
object [ "type" .=. "unauthorized" ]
toJSON BadCredentials =
object [ "type" .= ("incorrect_credentials" :: Text) ]
object [ "type" .=. "incorrect_credentials" ]
toJSON (DBError t) =
object [ "type" .= ("database_error" :: Text)
object [ "type" .=. "database_error"
, "description" .= t
]
toJSON UserExists =
object [ "type" .= ("user_exists" :: Text)
, "description" .= ("This email is already registered." :: Text)
object [ "type" .=. "user_exists"
, "description" .=. "This email is already registered."
]
toJSON (BadRequest desc) =
object [ "type" .= ("bad_request" :: Text)
object [ "type" .=. "bad_request"
, "description" .= desc
]
toJSON (NotFound id') =
object [ "type" .= ("not_found" :: Text)
object [ "type" .=. "not_found"
, "id" .= toText id'
, "description" .= ("Entity not found" :: Text)
, "description" .=. "Entity not found"
]
instance ToJSON ViewErrors where
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment