From f3205b0b075de2af746f3429e70dfdb316c6b5b5 Mon Sep 17 00:00:00 2001 From: ahmedakef Date: Wed, 8 Jan 2025 19:55:25 +0100 Subject: [PATCH] enhance error handling in HTTP helpers; improve error messages for better clarity --- frontend/src/Helpers/Http.elm | 11 +++++++++-- frontend/src/Steps/Steps.elm | 4 ++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/frontend/src/Helpers/Http.elm b/frontend/src/Helpers/Http.elm index 0f9a242..2396835 100644 --- a/frontend/src/Helpers/Http.elm +++ b/frontend/src/Helpers/Http.elm @@ -2,20 +2,27 @@ module Helpers.Http exposing (..) import Http + errorToString : Http.Error -> String errorToString error = case error of Http.BadUrl url -> "The URL " ++ url ++ " was invalid" + Http.Timeout -> "Unable to reach the server, try again" + Http.NetworkError -> "Unable to reach the server, check your network connection" + Http.BadStatus 500 -> "The server had a problem, try again later" + Http.BadStatus 400 -> "Verify your information and try again" - Http.BadStatus _ -> - "Unknown error" + + Http.BadStatus num -> + "Unknown error" ++ String.fromInt num + Http.BadBody errorMessage -> errorMessage diff --git a/frontend/src/Steps/Steps.elm b/frontend/src/Steps/Steps.elm index c816a78..c6f9501 100644 --- a/frontend/src/Steps/Steps.elm +++ b/frontend/src/Steps/Steps.elm @@ -72,7 +72,7 @@ update msg state = ( Success { successState | steps = steps }, Cmd.none ) Err err -> - ( Failure (err |> HttpHelper.errorToString), Cmd.none ) + ( Failure ("error while getting program execution steps" ++ HttpHelper.errorToString err), Cmd.none ) GotSourceCode sourceCodeResult -> case sourceCodeResult of @@ -80,7 +80,7 @@ update msg state = ( Success { successState | sourceCode = sourceCode }, Cmd.none ) Err err -> - ( Failure (err |> HttpHelper.errorToString), Cmd.none ) + ( Failure ("error while reading program source code" ++ HttpHelper.errorToString err), Cmd.none ) Next -> if successState.position + 1 > List.length successState.steps then