Skip to content

Commit

Permalink
[#500] Trails: Rename ORError to TrailsError, this was missed when co…
Browse files Browse the repository at this point in the history
…py pasting code from the OR to initalise the Trails Service.

This issue was identified in code review.
  • Loading branch information
a-stacey committed Jul 17, 2019
1 parent 0e30f90 commit 034cbad
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
26 changes: 13 additions & 13 deletions projects/trails/src/Mirza/Trails/Service.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ import Data.Swagger

-- Convenience class for contexts which require all possible error types that
-- could be thrown through the handlers.
class (AsORError err, AsSqlError err)
class (AsTrailsError err, AsSqlError err)
=> APIPossibleErrors err where
instance (AsORError err, AsSqlError err)
instance (AsTrailsError err, AsSqlError err)
=> APIPossibleErrors err


Expand All @@ -52,12 +52,12 @@ publicServer =



appMToHandler :: (HasLogging context) => context -> AppM context ORError x -> Handler x
appMToHandler :: (HasLogging context) => context -> AppM context TrailsError x -> Handler x
appMToHandler context act = do
res <- liftIO $ runAppM context act
case res of
Left err ->
runKatipContextT (context ^. katipLogEnv) () (context ^. katipNamespace) (orErrorToHttpError err)
runKatipContextT (context ^. katipLogEnv) () (context ^. katipNamespace) (trailsErrorToHttpError err)
Right a -> pure a


Expand Down Expand Up @@ -96,16 +96,16 @@ throwHttpError err httpStatus errorMessage = do
lift $ throwError $ httpStatus { errBody = errorMessage }


-- | Takes a ORError and converts it to an HTTP error.
orErrorToHttpError :: ORError -> KatipContextT Handler a
orErrorToHttpError orError =
let _httpError = throwHttpError orError
in case orError of
(DBErrorORE _) -> unexpectedError orError
(UnmatchedUniqueViolationORE _) -> unexpectedError orError
-- | Takes a TrailsError and converts it to an HTTP error.
trailsErrorToHttpError :: TrailsError -> KatipContextT Handler a
trailsErrorToHttpError trailsError =
let _httpError = throwHttpError trailsError
in case trailsError of
(DBErrorTE _) -> unexpectedError trailsError
(UnmatchedUniqueViolationTE _) -> unexpectedError trailsError

-- | A generic internal server error has occured. We include no more information in the result returned to the user to
-- limit further potential for exploitation, under the expectation that we log the errors to somewhere that is reviewed
-- regularly so that the development team are informed and can identify and patch the underlying issues.
unexpectedError :: ORError -> KatipContextT Handler a
unexpectedError orError = throwHttpError orError err500 "An unknown error has occured."
unexpectedError :: TrailsError -> KatipContextT Handler a
unexpectedError trailsError = throwHttpError trailsError err500 "An unknown error has occured."
10 changes: 5 additions & 5 deletions projects/trails/src/Mirza/Trails/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ instance HasKatipContext (TrailsContext) where
-- Error Types
-- *****************************************************************************

data ORError
= DBErrorORE SqlError
| UnmatchedUniqueViolationORE SqlError
data TrailsError
= DBErrorTE SqlError
| UnmatchedUniqueViolationTE SqlError
deriving (Show)
$(makeClassyPrisms ''ORError)
$(makeClassyPrisms ''TrailsError)

instance AsSqlError ORError where _SqlError = _DBErrorORE
instance AsSqlError TrailsError where _SqlError = _DBErrorTE

0 comments on commit 034cbad

Please sign in to comment.