Commit 37c94f6c authored by Alfredo Di Napoli's avatar Alfredo Di Napoli

InternalServerError -> FrontendError

parent 2730e32c
......@@ -29,6 +29,8 @@ import Servant.Server
import qualified Data.Aeson as JSON
import qualified Data.Text as T
import qualified Network.HTTP.Types.Status as HTTP
import qualified Data.Text.Lazy.Encoding as TE
import qualified Data.Text.Lazy as TL
$(deriveHttpStatusCode ''BackendErrorCode)
......@@ -48,11 +50,16 @@ backendErrorToFrontendError = \case
Just v -> T.pack v
InternalAuthenticationError authError
-> authErrorToFrontendError authError
InternalServerError _internalServerError
-> undefined
InternalServerError internalServerError
-> internalServerErrorToFrontendError internalServerError
InternalJobError jobError
-> jobErrorToFrontendError jobError
internalServerErrorToFrontendError :: ServerError -> FrontendError
internalServerErrorToFrontendError = \case
ServerError{..} ->
mkFrontendErr' (T.pack errReasonPhrase) $ FE_internal_server_error (TL.toStrict $ TE.decodeUtf8 $ errBody)
jobErrorToFrontendError :: JobError -> FrontendError
jobErrorToFrontendError = \case
InvalidIDType idTy -> mkFrontendErrNoDiagnostic $ FE_job_error_invalid_id_type idTy
......
......@@ -246,6 +246,10 @@ data instance ToFrontendErrorData 'EC_500__job_error_unknown_job =
FE_job_error_unknown_job { jeuj_job_id :: Int }
deriving (Show, Eq, Generic)
data instance ToFrontendErrorData 'EC_500__internal_server_error =
FE_internal_server_error { ise_error :: T.Text }
deriving (Show, Eq, Generic)
data instance ToFrontendErrorData 'EC_500__job_error_generic_exception =
FE_job_error_generic_exception { jege_error :: T.Text }
deriving (Show, Eq, Generic)
......@@ -316,6 +320,19 @@ instance FromJSON (ToFrontendErrorData 'EC_403__login_failed_error) where
lfe_node_id <- o .: "node_id"
pure FE_login_failed_error{..}
--
-- internal server errors
--
instance ToJSON (ToFrontendErrorData 'EC_500__internal_server_error) where
toJSON FE_internal_server_error{..} = object [ "error" .= toJSON ise_error ]
instance FromJSON (ToFrontendErrorData 'EC_500__internal_server_error) where
parseJSON = withObject "FE_internal_server_error" $ \o -> do
ise_error <- o .: "error"
pure FE_internal_server_error{..}
--
-- tree errors
--
......@@ -427,6 +444,11 @@ genFrontendErr be = do
uid <- arbitrary
pure $ mkFrontendErr' txt $ FE_login_failed_error nid uid
-- internal error
EC_500__internal_server_error
-> do err <- arbitrary
pure $ mkFrontendErr' txt $ FE_internal_server_error err
-- tree errors
EC_404__tree_error_root_not_found
-> pure $ mkFrontendErr' txt $ FE_tree_error_root_not_found
......@@ -500,6 +522,11 @@ instance FromJSON FrontendError where
(fe_data :: ToFrontendErrorData 'EC_403__login_failed_error) <- o .: "data"
pure FrontendError{..}
-- internal server error
EC_500__internal_server_error -> do
(fe_data :: ToFrontendErrorData 'EC_500__internal_server_error) <- o .: "data"
pure FrontendError{..}
-- tree errors
EC_404__tree_error_root_not_found -> do
(fe_data :: ToFrontendErrorData 'EC_404__tree_error_root_not_found) <- o .: "data"
......
......@@ -29,6 +29,8 @@ data BackendErrorCode
| EC_404__tree_error_root_not_found
| EC_404__tree_error_empty_root
| EC_500__tree_error_too_many_roots
-- internal server errors
| EC_500__internal_server_error
-- job errors
| EC_500__job_error_invalid_id_type
| EC_500__job_error_expired
......
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