freckle / yesod-auth-oauth2

OAuth2 authentication for yesod
MIT License
71 stars 53 forks source link

Consolidate all errors, use onErrorHtml #142

Closed pbrisbin closed 3 years ago

pbrisbin commented 3 years ago

Prior to this commit, some errors would be thrown (missing parameter, invalid state, incorrect approot) while others would be handled via the set-message-redirect approach (handshake failure, fetch-token failure, etc).

This commit consolidates all of these cases into a single DispatchError type, and then uses MonadError (concretely ExceptT) to capture them all and handle them in one place ourselves.

It then updates that handling to:

The last two were just nice-to-haves that were cheap to add once the code was in this state.

Note that the use of MonadError requires a potentially "bad" orphan MonadUnliftIO instance for ExceptT, but I'd like to see that instance become a reality and think it needs some real-world experimentation to get there, so here I am.

pbrisbin commented 3 years ago

First commit is the thing, with a minimized diff. Subsequent diffs are refactor.