summaryrefslogtreecommitdiffhomepage
path: root/src/Plugins
diff options
context:
space:
mode:
authorBen Boeckel <mathstuf@gmail.com>2014-02-05 11:03:58 -0500
committerBen Boeckel <mathstuf@gmail.com>2014-02-05 11:03:58 -0500
commita14e8888272a331bb6cdb1abadb03d4f5f22ec1d (patch)
tree884c8b8caa49467c92d044de3e9d46fe1750f5ff /src/Plugins
parentbfc7362182f75cba63866cc915f9dbe62ebe9a42 (diff)
downloadxmobar-a14e8888272a331bb6cdb1abadb03d4f5f22ec1d.tar.gz
xmobar-a14e8888272a331bb6cdb1abadb03d4f5f22ec1d.tar.bz2
Handle errors better in Weather plugin
Diffstat (limited to 'src/Plugins')
-rw-r--r--src/Plugins/Monitors/Weather.hs26
1 files changed, 14 insertions, 12 deletions
diff --git a/src/Plugins/Monitors/Weather.hs b/src/Plugins/Monitors/Weather.hs
index 4030352..f2cc131 100644
--- a/src/Plugins/Monitors/Weather.hs
+++ b/src/Plugins/Monitors/Weather.hs
@@ -133,8 +133,7 @@ stationUrl station = defUrl ++ station ++ ".TXT"
getData :: String -> IO String
getData station = do
let request = getRequest (stationUrl station)
- result <- simpleHTTP request
- catch (getResponseBody result) errHandler
+ catch (simpleHTTP request >>= getResponseBody) errHandler
where errHandler :: IOException -> IO String
errHandler _ = return "<Could not retrieve data>"
@@ -155,13 +154,16 @@ weatherReady :: [String] -> Monitor Bool
weatherReady str = do
let station = head str
request = headRequest (stationUrl station)
- result <- io $ simpleHTTP request
- case result of
- Left _ -> return False
- Right response -> do
- case rspCode response of
- -- Permission or network errors are failures; anything else is
- -- recoverable.
- (4, _, _) -> return False
- (5, _, _) -> return False
- (_, _, _) -> return True
+ io $ catch (simpleHTTP request >>= checkResult) errHandler
+ where errHandler :: IOException -> IO Bool
+ errHandler _ = return False
+ checkResult result = do
+ case result of
+ Left _ -> return False
+ Right response -> do
+ case rspCode response of
+ -- Permission or network errors are failures; anything
+ -- else is recoverable.
+ (4, _, _) -> return False
+ (5, _, _) -> return False
+ (_, _, _) -> return True