~alcinnz/hurl

7cea1667ec30438e60daf696347174dccda8dee3 — Adrian Cochrane 1 year, 7 months ago a841435
Localize HTTP errorcodes!
2 files changed, 62 insertions(+), 5 deletions(-)

M src/Network/URI/Fetch.hs
M src/Network/URI/Messages.hs
M src/Network/URI/Fetch.hs => src/Network/URI/Fetch.hs +3 -1
@@ 554,7 554,9 @@ fetchHTTPCached session shouldCache accept@(defaultMIME:_) rawUri cbReq cbResp =
                        Just location <- lookup "location" $ HTTP.responseHeaders response,
                        Just uri' <- parseURIReference $ C8.unpack location ->
                    return $ Left $ relativeTo uri' uri
                (Status _ msg, "", _) -> return $ Right (Txt.pack mimeERR, B.fromStrict msg)
                (Status code msg, "", _) -> return $ Right (Txt.pack mimeERR,
                    B.fromStrict $ C8.pack $
                        trans (locale session) $ HTTPStatus code $ C8.unpack msg)
                (_, body, (mimetype:_)) -> do
                    cacheHTTP uri response
                    forkIO cleanCacheHTTP -- Try to keep diskspace down...

M src/Network/URI/Messages.hs => src/Network/URI/Messages.hs +59 -4
@@ 88,6 88,7 @@ trans ("en":_) (Http (HttpExceptionRequest _ (InternalException e))) = case from
    Just ConnectionNotEstablished ->
        "Attempted to send or recieve data before establishing secure connection!"
    Nothing -> "Internal error: " ++ displayException e
#endif
trans ("en":_) (GeminiError '1' '1' label) =
    "<form><label>" ++ label ++ "<input type=password></form>" 
trans ("en":_) (GeminiError '1' _ label) = "<form><label>" ++ label ++ "<input></form>"


@@ 96,8 97,8 @@ trans ("en":_) (GeminiError '4' '2' _) = "Program error!"
trans ("en":_) (GeminiError '4' '3' _) = "Proxy error!"
trans ("en":_) (GeminiError '4' '4' timeout) =
    "Site busy! Please reload after at least " ++ timeout ++ " seconds"
trans ("en":_) (GeminiError '5' '1' _) = "Page not found!"
trans ("en":_) (GeminiError '5' '2' _) = "Page deleted!"
trans ("en":_) (GeminiError '5' '1' _) = "Page not found! Try the <a href='/'>homepage</a>."
trans ("en":_) (GeminiError '5' '2' _) = "Page deleted! Try the <a href='/'>homepage</a>."
trans ("en":_) (GeminiError '5' '3' _) = "Contacted wrong server!"
trans ("en":_) (GeminiError '5' '9' _) = "Malformed request, my bad!"
trans ("en":_) (GeminiError '6' '1' _) = "<form><label>Authentication required" ++


@@ 107,7 108,61 @@ trans ("en":_) (GeminiError '6' '2' _) = "<form><label>Authentication required" 
trans ("en":_) (GeminiError '6' _ _) = "<form><label>Authentication required" ++
    "<input type='-argo-keypair' -argo-error='Invalid account!'></form>"
trans ("en":_) (GeminiError _ _ error) = error
#endif
trans ("en":_) (HTTPStatus 400 _) = "I sent a bad request, according to this site."
trans ("en":_) (HTTPStatus 401 _) = "Authentication required!" -- FIXME: Support HTTP Basic Auth.
trans ("en":_) (HTTPStatus 402 _) = "Payment required!"
trans ("en":_) (HTTPStatus 403 _) = "Access denied!"
trans ("en":_) (HTTPStatus 404 _) = "Page not found! Try the <a href='/'>homepage</a>."
trans ("en":_) (HTTPStatus 405 _) = "Bad webform for this destination webaddress! " ++
    "<em>Method not allowed</em>."
trans ("en":_) (HTTPStatus 406 _) = "No representation available for given criteria!"
trans ("en":_) (HTTPStatus 407 _) = "Authentication into proxyserver required!"
trans ("en":_) (HTTPStatus 408 _) = "The site took too long to connect! <em>(HTTP 408)</em>"
trans ("en":_) (HTTPStatus 409 _) = "Request is based on outdated state!"
trans ("en":_) (HTTPStatus 410 _) = "Page deleted! Try the <a href='/'>homepage</a>."
trans ("en":_) (HTTPStatus 411 _) = "I sent a bad request, according to this site." ++
    "<em>(Missing <code>Content-Length</code> header)</em>"
trans ("en":_) (HTTPStatus 412 _) = "Webpage doesn't meet our preconditions."
trans ("en":_) (HTTPStatus 413 _) = "Payload too large, please upload a smaller file!"
trans ("en":_) (HTTPStatus 414 _) = "Web address is too long for the site!"
trans ("en":_) (HTTPStatus 415 _) = "No representation available for supported filetypes!"
trans ("en":_) (HTTPStatus 416 _) = "Invalid byte-range of requested resource!"
trans ("en":_) (HTTPStatus 417 _) = "Site cannot satisfy our stated expectations!"
trans ("en":_) (HTTPStatus 418 _) = unlines [
    "<p>I'm a little teapot<br/>",
    "Short and stout<br/>",
    "Here is my handle<br/>",
    "And here is my spout.</p>>",
    "<p>When I get all steamed up<br/>",
    "Hear me shout<br/>",
    "<q>Tip me over<br/>",
    "And pour me out!</q></p>"
  ]
trans ("en":_) (HTTPStatus 421 _) = "Contacted wrong server!"
trans ("en":_) (HTTPStatus 422 _) = "Invalid <strong>WebDAV</strong> request!"
trans ("en":_) (HTTPStatus 423 _) = "<strong>WebDAV</strong> resource is locked!"
trans ("en":_) (HTTPStatus 424 _) = "Failed due to previous failure!"
trans ("en":_) (HTTPStatus 425 _) = "Site requires stronger security on our request!"
trans ("en":_) (HTTPStatus 426 _) = "Site requires newer networking-protocols!"
trans ("en":_) (HTTPStatus 428 _) = "Site requires additional protection to avoid loosing changes!"
trans ("en":_) (HTTPStatus 429 _) = "We sent this site too many requests for it to cope with!"
trans ("en":_) (HTTPStatus 431 _) = "I sent more auxiliary data than this site can cope with!"
trans ("en":_) (HTTPStatus 451 _) = "Requested page cannot legally be provided!"

trans ("en":_) (HTTPStatus 500 _) = "The site experienced an error generating this webpage. <em>The webmasters have probably already been automatically notified.</em>"
trans ("en":_) (HTTPStatus 501 _) = "Bad webform for this destination webaddress! " ++ 
    "<em>Method not implemented</em>."
trans ("en":_) (HTTPStatus 502 _) = "Proxyserver got a malformed response!"
trans ("en":_) (HTTPStatus 503 _) = "The site is not available right now!"
trans ("en":_) (HTTPStatus 504 _) = "The site took too long to respond! <em>(Behind proxy)</em>"
trans ("en":_) (HTTPStatus 505 _) = "The site does not speak the language as me! " ++
    "<em>(Unsupported HTTP version)</em>"
trans ("en":_) (HTTPStatus 506 _) = "The site is misconfigured!"
trans ("en":_) (HTTPStatus 507 _) = "Insufficient <strong>WebDAV</strong> storage!"
trans ("en":_) (HTTPStatus 508 _) = "<strong>WebDAV</strong> loop detected!"
trans ("en":_) (HTTPStatus 510 _) = "Further request extensions required!"
trans ("en":_) (HTTPStatus 511 _) = "Authentication into network required!"
trans ("en":_) (HTTPStatus _ error) = error -- TODO localize
--- END LOCALIZATION

trans (_:locales) err = trans locales err


@@ 115,7 170,7 @@ trans [] err = trans ["en"] err

data Errors = UnsupportedScheme String | UnsupportedMIME String | RequiresInstall String String
    | OpenedWith String | ReadFailed String | RawXML String | MalformedResponse
    | ExcessiveRedirects | GeminiError Char Char String
    | ExcessiveRedirects | HTTPStatus Int String | GeminiError Char Char String
#if WITH_HTTP_URI
    | Http HttpException
#endif