handleLoginError :: J.AuthFailure -> H ()
handleLoginError err =
  case err of
    J.DuplicateLogin -> failLogin dupeError
    J.UnknownUser    -> failLogin failedPassOrUserError
    J.WrongPassword  -> failLogin failedPassOrUserError
  where
    dupeError             = "Duplicate login"
    failedPassOrUserError = "Unknown user or wrong password"

    failLogin :: T.Text -> H ()
    failLogin err = do
      jsonResponse
      modifyResponse $ setResponseStatus 401 "bad login"
      writeJSON $ object [ "error" .= err]
handleLoginError :: J.AuthFailure -> H ()
handleLoginError err =
  case err of
    J.DuplicateLogin -> failLogin dupeError
    J.UnknownUser    -> failLogin failedPassOrUserError
    J.WrongPassword  -> failLogin failedPassOrUserError
  where
    dupeError             = "Duplicate login"
    failedPassOrUserError = "Unknown user or wrong password"

    failLogin :: T.Text -> H ()
    failLogin err = do
      jsonResponse
      modifyResponse $ setResponseStatus 401 "bad login"
      writeJSON $ object [ "error" .= err]
handleLoginError err =
  case err of
    J.DuplicateLogin -> failLogin dupeError
    J.UnknownUser    -> failLogin failedPassOrUserError
    J.WrongPassword  -> failLogin failedPassOrUserError
  where
    dupeError             = "Duplicate login"
    failedPassOrUserError = "Unknown user or wrong password"

    failLogin :: T.Text -> H ()
    failLogin err = do
      jsonResponse
      modifyResponse $ setResponseStatus 401 "bad login"
      writeJSON $ object [ "error" .= err]