-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor to exceptions #31
base: master
Are you sure you want to change the base?
Conversation
@@ -204,7 +206,7 @@ clearRedisCache ctxt = R.runRedis (_redis ctxt) (rdelstar "wordpress:*") | |||
|
|||
unobj :: Value -> Object | |||
unobj (Object x) = x | |||
unobj _ = error "Not an object" | |||
unobj _ = throw NotAnObject |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is silly, should've just stayed an error (it's only for testing)
("custom-endpoint-array", ctxt) `shouldRenderContaining` "2014-10-01" | ||
("custom-endpoint-array", ctxt) `shouldRenderContaining` "2014-10-02" | ||
("custom-endpoint-array", ctxt) `shouldRenderContaining` "2014-10-15" | ||
it "should be able to reference fields from the custom endpoint in another custom endpoint query" $ do | ||
("custom-endpoint-array", ctxt) `rendersSameAs` "custom-endpoint-enter-the-matrix" | ||
it "should handle 404s without blowing up" $ | ||
("custom-endpoint-404", ctxt) `shouldRenderContaining` "404" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works, but the wreq/http-client exception has a LOT of information that doesn't belong in the HTML debugging comment. Right now all the information about the request is in there.
where getAndCache = do jsonBlob <- wpRequest wpKey | ||
wpCacheSet wpKey jsonBlob | ||
stopReqMutex wpKey | ||
return jsonBlob |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is so much easier to look at! yay!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 👍
|
||
errorUnless :: Text -> IO (CacheResult a) -> IO (Either StatusCode a) | ||
catch action (\(e :: CacheInProgress) -> CC.threadDelay 100000 >> retryUnless action) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So here I'm caching this CacheInProgress
exception, but I'm not actually throwing it in startMutex
yet
(There are no tests that exercise this stuff!)
Tests currently pass, but still some work to do. Would appreciate comments, suggestions.
It seems like I ought to be able to pull out the "log and comment" parts of the exception handling into a function, but I'm not sure how yet.
I like that the parts that are throwing exceptions seem much simpler now, but all the complexity is just being offloaded to the Fills. :/
Biggest problem is that I made this
CacheInProgress
exception that the retry function catches, but I'm not actually throwing it in the mutex function yet. So still need to figure that out.