A music player that connects to your cloud/distributed storage.
5
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add better error handling for sources

+89 -75
+3 -1
src/Applications/Brain/Sources/Processing/Common.elm
··· 111 111 "Got a faulty response from this source. Use the developer console to get more info." 112 112 113 113 BadBody response -> 114 - Services.parseErrorResponse service response 114 + response 115 + |> Services.parseErrorResponse service 116 + |> Maybe.withDefault (translateHttpError service <| BadStatus 0)
+9 -1
src/Applications/UI.elm
··· 1299 1299 notificationId = 1300 1300 Notifications.id notification 1301 1301 1302 + newNotifications = 1303 + List.filter 1304 + (\n -> Notifications.kind n /= Notifications.Error) 1305 + model.notifications 1306 + 1302 1307 sources = 1303 1308 model.sources 1304 1309 ··· 1308 1313 , processingError = Nothing 1309 1314 , processingNotificationId = Just notificationId 1310 1315 } 1316 + 1317 + newModel = 1318 + { model | notifications = newNotifications, sources = newSources } 1311 1319 in 1312 1320 [ ( "origin" 1313 1321 , Json.Encode.string (Common.urlOrigin model.url) ··· 1319 1327 |> Json.Encode.object 1320 1328 |> Alien.broadcast Alien.ProcessSources 1321 1329 |> Ports.toBrain 1322 - |> returnWithModel { model | sources = newSources } 1330 + |> returnWithModel newModel 1323 1331 |> andThen (showNotification notification) 1324 1332 1325 1333 RemoveSourceFromCollection args ->
+21 -1
src/Library/Common.elm
··· 1 - module Common exposing (Switch(..), backToIndex, boolFromString, boolToString, queryString, urlOrigin) 1 + module Common exposing (Switch(..), backToIndex, boolFromString, boolToString, queryString, translateHttpResponse, urlOrigin) 2 2 3 + import Http 3 4 import Tuple.Ext as Tuple 4 5 import Url exposing (Protocol(..), Url) 5 6 import Url.Builder as Url ··· 49 50 queryString : List ( String, String ) -> String 50 51 queryString = 51 52 List.map (Tuple.uncurry Url.string) >> Url.toQuery 53 + 54 + 55 + translateHttpResponse : Http.Response String -> Result Http.Error String 56 + translateHttpResponse response = 57 + case response of 58 + Http.BadUrl_ u -> 59 + Err (Http.BadUrl u) 60 + 61 + Http.Timeout_ -> 62 + Err Http.Timeout 63 + 64 + Http.NetworkError_ -> 65 + Err Http.NetworkError 66 + 67 + Http.BadStatus_ m body -> 68 + Err (Http.BadBody body) 69 + 70 + Http.GoodStatus_ m body -> 71 + Ok body 52 72 53 73 54 74 urlOrigin : Url -> String
+1 -1
src/Library/Sources/Services.elm
··· 101 101 WebDav.makeTree 102 102 103 103 104 - parseErrorResponse : Service -> String -> String 104 + parseErrorResponse : Service -> String -> Maybe String 105 105 parseErrorResponse service = 106 106 case service of 107 107 AmazonS3 ->
+3 -2
src/Library/Sources/Services/AmazonS3.elm
··· 8 8 9 9 -} 10 10 11 + import Common 11 12 import Dict 12 13 import Http 13 14 import Sources exposing (Property, SourceData) ··· 139 140 in 140 141 Http.get 141 142 { url = url 142 - , expect = Http.expectString resultMsg 143 + , expect = Http.expectStringResponse resultMsg Common.translateHttpResponse 143 144 } 144 145 145 146 ··· 155 156 Parser.parseTreeResponse 156 157 157 158 158 - parseErrorResponse : String -> String 159 + parseErrorResponse : String -> Maybe String 159 160 parseErrorResponse = 160 161 Parser.parseErrorResponse 161 162
+2 -6
src/Library/Sources/Services/AmazonS3/Parser.elm
··· 52 52 -- ERROR 53 53 54 54 55 - parseErrorResponse : String -> String 55 + parseErrorResponse : String -> Maybe String 56 56 parseErrorResponse response = 57 57 response 58 58 |> decodeString errorMessagesDecoder 59 59 |> Result.toMaybe 60 - |> Maybe.andThen List.head 61 - |> Maybe.withDefault "Invalid request" 62 60 63 61 64 - errorMessagesDecoder : Decoder (List String) 62 + errorMessagesDecoder : Decoder String 65 63 errorMessagesDecoder = 66 64 string 67 65 |> single 68 66 |> path [ "Message" ] 69 - |> list 70 - |> path [ "Error" ]
+2 -6
src/Library/Sources/Services/Azure/BlobParser.elm
··· 50 50 -- ERROR 51 51 52 52 53 - parseErrorResponse : String -> String 53 + parseErrorResponse : String -> Maybe String 54 54 parseErrorResponse response = 55 55 response 56 56 |> decodeString errorMessagesDecoder 57 57 |> Result.toMaybe 58 - |> Maybe.andThen List.head 59 - |> Maybe.withDefault "Invalid request" 60 58 61 59 62 - errorMessagesDecoder : Decoder (List String) 60 + errorMessagesDecoder : Decoder String 63 61 errorMessagesDecoder = 64 62 string 65 63 |> single 66 64 |> path [ "Message" ] 67 - |> list 68 - |> path [ "Error" ]
+2 -6
src/Library/Sources/Services/Azure/FileParser.elm
··· 86 86 -- ERROR 87 87 88 88 89 - parseErrorResponse : String -> String 89 + parseErrorResponse : String -> Maybe String 90 90 parseErrorResponse response = 91 91 response 92 92 |> decodeString errorMessagesDecoder 93 93 |> Result.toMaybe 94 - |> Maybe.andThen List.head 95 - |> Maybe.withDefault "Invalid request" 96 94 97 95 98 - errorMessagesDecoder : Decoder (List String) 96 + errorMessagesDecoder : Decoder String 99 97 errorMessagesDecoder = 100 98 string 101 99 |> single 102 100 |> path [ "Message" ] 103 - |> list 104 - |> path [ "Error" ]
+4 -3
src/Library/Sources/Services/AzureBlob.elm
··· 8 8 9 9 -} 10 10 11 + import Common 11 12 import Dict 12 13 import Http 13 14 import Sources exposing (Property, SourceData) ··· 93 94 94 95 -} 95 96 makeTree : SourceData -> Marker -> Time.Posix -> (Result Http.Error String -> msg) -> Cmd msg 96 - makeTree srcData marker currentTime toMsg = 97 + makeTree srcData marker currentTime resultMsg = 97 98 let 98 99 directoryPath = 99 100 srcData ··· 117 118 in 118 119 Http.get 119 120 { url = url 120 - , expect = Http.expectString toMsg 121 + , expect = Http.expectStringResponse resultMsg Common.translateHttpResponse 121 122 } 122 123 123 124 ··· 133 134 Parser.parseTreeResponse 134 135 135 136 136 - parseErrorResponse : String -> String 137 + parseErrorResponse : String -> Maybe String 137 138 parseErrorResponse = 138 139 Parser.parseErrorResponse 139 140
+4 -3
src/Library/Sources/Services/AzureFile.elm
··· 8 8 9 9 -} 10 10 11 + import Common 11 12 import Dict 12 13 import Http 13 14 import Sources exposing (Property, SourceData) ··· 94 95 95 96 -} 96 97 makeTree : SourceData -> Marker -> Time.Posix -> (Result Http.Error String -> msg) -> Cmd msg 97 - makeTree srcData marker currentTime toMsg = 98 + makeTree srcData marker currentTime resultMsg = 98 99 let 99 100 directoryPathFromSrcData = 100 101 srcData ··· 121 122 in 122 123 Http.get 123 124 { url = url 124 - , expect = Http.expectString toMsg 125 + , expect = Http.expectStringResponse resultMsg Common.translateHttpResponse 125 126 } 126 127 127 128 ··· 137 138 Parser.parseTreeResponse 138 139 139 140 140 - parseErrorResponse : String -> String 141 + parseErrorResponse : String -> Maybe String 141 142 parseErrorResponse = 142 143 Parser.parseErrorResponse 143 144
+3 -3
src/Library/Sources/Services/Dropbox.elm
··· 125 125 126 126 -} 127 127 makeTree : SourceData -> Marker -> Time.Posix -> (Result Http.Error String -> msg) -> Cmd msg 128 - makeTree srcData marker currentTime toMsg = 128 + makeTree srcData marker currentTime resultMsg = 129 129 let 130 130 accessToken = 131 131 Dict.fetch "accessToken" "" srcData ··· 164 164 , headers = [ Http.header "Authorization" ("Bearer " ++ accessToken) ] 165 165 , url = url 166 166 , body = body 167 - , expect = Http.expectString toMsg 167 + , expect = Http.expectStringResponse resultMsg Common.translateHttpResponse 168 168 , timeout = Nothing 169 169 , tracker = Nothing 170 170 } ··· 198 198 Parser.parseTreeResponse 199 199 200 200 201 - parseErrorResponse : String -> String 201 + parseErrorResponse : String -> Maybe String 202 202 parseErrorResponse = 203 203 Parser.parseErrorResponse 204 204
+3 -1
src/Library/Sources/Services/Dropbox/Parser.elm
··· 36 36 -- Error 37 37 38 38 39 - parseErrorResponse : String -> String 39 + parseErrorResponse : String -> Maybe String 40 40 parseErrorResponse response = 41 41 response 42 + |> decodeString (field "error_summary" string) 43 + |> Result.toMaybe
+5 -5
src/Library/Sources/Services/Google.elm
··· 133 133 Or if we don't have an access token yet, get one. 134 134 -} 135 135 prepare : String -> SourceData -> Marker -> (Result Http.Error String -> msg) -> Maybe (Cmd msg) 136 - prepare origin srcData _ toMsg = 136 + prepare origin srcData _ resultMsg = 137 137 let 138 138 maybeCode = 139 139 Dict.get "authCode" srcData ··· 166 166 (Just << Http.post) 167 167 { url = url 168 168 , body = Http.emptyBody 169 - , expect = Http.expectString toMsg 169 + , expect = Http.expectStringResponse resultMsg Common.translateHttpResponse 170 170 } 171 171 172 172 ··· 181 181 182 182 -} 183 183 makeTree : SourceData -> Marker -> Time.Posix -> (Result Http.Error String -> msg) -> Cmd msg 184 - makeTree srcData marker currentTime toMsg = 184 + makeTree srcData marker currentTime resultMsg = 185 185 let 186 186 accessToken = 187 187 Dict.fetch "accessToken" "" srcData ··· 223 223 , headers = [ Http.header "Authorization" ("Bearer " ++ accessToken) ] 224 224 , url = "https://www.googleapis.com/drive/v3/files" ++ queryString 225 225 , body = Http.emptyBody 226 - , expect = Http.expectString toMsg 226 + , expect = Http.expectStringResponse resultMsg Common.translateHttpResponse 227 227 , timeout = Nothing 228 228 , tracker = Nothing 229 229 } ··· 241 241 Parser.parseTreeResponse 242 242 243 243 244 - parseErrorResponse : String -> String 244 + parseErrorResponse : String -> Maybe String 245 245 parseErrorResponse = 246 246 Parser.parseErrorResponse 247 247
+4 -2
src/Library/Sources/Services/Google/Parser.elm
··· 82 82 83 83 84 84 85 - -- Error 85 + -- ERROR 86 86 87 87 88 - parseErrorResponse : String -> String 88 + parseErrorResponse : String -> Maybe String 89 89 parseErrorResponse response = 90 90 response 91 + |> decodeString (at [ "error", "message" ] string) 92 + |> Result.toMaybe
+6 -29
src/Library/Sources/Services/Ipfs.elm
··· 196 196 , headers = [] 197 197 , url = gateway ++ "/api/v0/ls?arg=" ++ ipfsHash ++ "&encoding=json" 198 198 , body = Http.emptyBody 199 - , resolver = Http.stringResolver ipfsResolver 199 + , resolver = Http.stringResolver Common.translateHttpResponse 200 200 , timeout = Just (60 * 15) 201 201 } 202 202 ) ··· 215 215 Http.NetworkError_ -> 216 216 Err Http.NetworkError 217 217 218 - Http.BadStatus_ m body -> 219 - body 220 - |> Json.decodeString (Json.field "Message" Json.string) 221 - |> Result.map Http.BadBody 222 - |> Result.withDefault (Http.BadStatus m.statusCode) 223 - |> Err 218 + Http.BadStatus_ _ body -> 219 + Err (Http.BadBody body) 224 220 225 - Http.GoodStatus_ m body -> 221 + Http.GoodStatus_ _ body -> 226 222 body 227 223 |> Json.decodeString (Json.field "Path" Json.string) 228 224 |> Result.map (\hash -> { ipfsHash = hash }) 229 225 |> Result.mapError (Json.errorToString >> Http.BadBody) 230 226 231 227 232 - ipfsResolver : Http.Response String -> Result Http.Error String 233 - ipfsResolver response = 234 - case response of 235 - Http.BadUrl_ u -> 236 - Err (Http.BadUrl u) 237 - 238 - Http.Timeout_ -> 239 - Err Http.Timeout 240 - 241 - Http.NetworkError_ -> 242 - Err Http.NetworkError 243 - 244 - Http.BadStatus_ m body -> 245 - Err (Http.BadStatus m.statusCode) 246 - 247 - Http.GoodStatus_ m body -> 248 - Ok body 249 - 250 - 251 228 {-| Re-export parser functions. 252 229 -} 253 230 parsePreparationResponse : String -> SourceData -> Marker -> PrepationAnswer Marker ··· 260 237 Parser.parseTreeResponse 261 238 262 239 263 - parseErrorResponse : String -> String 240 + parseErrorResponse : String -> Maybe String 264 241 parseErrorResponse = 265 - identity 242 + Parser.parseErrorResponse 266 243 267 244 268 245
+12 -1
src/Library/Sources/Services/Ipfs/Parser.elm
··· 1 - module Sources.Services.Ipfs.Parser exposing (Link, linkDecoder, parseCloudflareDnsResult, parseTreeResponse, treeDecoder) 1 + module Sources.Services.Ipfs.Parser exposing (Link, linkDecoder, parseCloudflareDnsResult, parseErrorResponse, parseTreeResponse, treeDecoder) 2 2 3 3 import Dict 4 4 import Json.Decode exposing (..) ··· 94 94 (field "Hash" string) 95 95 (field "Name" string) 96 96 (field "Type" int) 97 + 98 + 99 + 100 + -- ERRORS 101 + 102 + 103 + parseErrorResponse : String -> Maybe String 104 + parseErrorResponse response = 105 + response 106 + |> decodeString (field "Message" string) 107 + |> Result.toMaybe
+3 -2
src/Library/Sources/Services/WebDav.elm
··· 9 9 -} 10 10 11 11 import Base64 12 + import Common 12 13 import Dict 13 14 import Dict.Ext as Dict 14 15 import Http ··· 121 122 , headers = [ Http.header "Authorization" auth, Http.header "Depth" "1" ] 122 123 , url = url { addAuth = False } srcData directory 123 124 , body = Http.emptyBody 124 - , expect = Http.expectString resultMsg 125 + , expect = Http.expectStringResponse resultMsg Common.translateHttpResponse 125 126 , timeout = Nothing 126 127 , tracker = Nothing 127 128 } ··· 139 140 Parser.parseTreeResponse 140 141 141 142 142 - parseErrorResponse : String -> String 143 + parseErrorResponse : String -> Maybe String 143 144 parseErrorResponse = 144 145 Parser.parseErrorResponse 145 146
+2 -2
src/Library/Sources/Services/WebDav/Parser.elm
··· 78 78 -- ERROR 79 79 80 80 81 - parseErrorResponse : String -> String 81 + parseErrorResponse : String -> Maybe String 82 82 parseErrorResponse = 83 - identity 83 + Just