diff options
author | Ben Boeckel <mathstuf@gmail.com> | 2014-02-05 11:03:58 -0500 |
---|---|---|
committer | Ben Boeckel <mathstuf@gmail.com> | 2014-02-05 11:03:58 -0500 |
commit | a14e8888272a331bb6cdb1abadb03d4f5f22ec1d (patch) | |
tree | 884c8b8caa49467c92d044de3e9d46fe1750f5ff /src | |
parent | bfc7362182f75cba63866cc915f9dbe62ebe9a42 (diff) | |
download | xmobar-a14e8888272a331bb6cdb1abadb03d4f5f22ec1d.tar.gz xmobar-a14e8888272a331bb6cdb1abadb03d4f5f22ec1d.tar.bz2 |
Handle errors better in Weather plugin
Diffstat (limited to 'src')
-rw-r--r-- | src/Plugins/Monitors/Weather.hs | 26 |
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 |