salvia-1.0.0: Modular web application framework.

Network.Salvia.Handler.Error

Synopsis

Documentation

hError :: (HttpM Response m, SendM m) => Status -> m ()Source

The hError handler enables the creation of a default style of error responses for the specified HTTP Status code.

hCustomError :: (HttpM Response m, SendM m) => Status -> String -> m ()Source

Like hError but with a custom error message.

hIOError :: (HttpM Response m, SendM m) => IOError -> m ()Source

Map an IOError to a default style error response.

The mapping from an IO error to an error response is rather straightforward:

  | isDoesNotExistError e = hError NotFound
  | isAlreadyInUseError e = hError ServiceUnavailable
  | isPermissionError   e = hError Forbidden
  | True                  = hError InternalServerError

hSafeIO :: (MonadIO m, HttpM Response m, SendM m) => IO a -> (a -> m ()) -> m ()Source

Execute an handler with the result of an IO action. When the IO actions fails a default error handler will be executed.

catchIO :: MonadIO m => IO a -> a -> m aSource

Utility function to easily catch IO errors.