Skip to content

Commit 5e7a0d9

Browse files
committed
fix(error messages): cli http request errors should show a summary with http status and message
1 parent aad1fdd commit 5e7a0d9

File tree

1 file changed

+23
-19
lines changed

1 file changed

+23
-19
lines changed

unison-cli/src/Unison/CommandLine/OutputMessages.hs

+23-19
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ import Unison.Term (Term)
138138
import Unison.Term qualified as Term
139139
import Unison.Type (Type)
140140
import Unison.UnisonFile qualified as UF
141+
import Unison.Util.ColorText qualified
141142
import Unison.Util.Conflicted (Conflicted (..))
142143
import Unison.Util.Defn (Defn (..))
143144
import Unison.Util.Defns (Defns (..))
@@ -971,7 +972,6 @@ notifyUser dir = \case
971972
-- defs in the codebase. In some cases it's fine for bindings to
972973
-- shadow codebase names, but you don't want it to capture them in
973974
-- the decompiled output.
974-
975975
let prettyBindings =
976976
P.bracket . P.lines $
977977
P.wrap "The watch expression(s) reference these definitions:"
@@ -1771,16 +1771,16 @@ notifyUser dir = \case
17711771
<> P.newline
17721772
<> P.indentN 2 (P.pshown response)
17731773
Servant.FailureResponse request response ->
1774-
P.wrap "Oops, I received an unexpected status code from the server."
1774+
unexpectedServerResponse response
17751775
<> P.newline
17761776
<> P.newline
1777-
<> P.wrap "Here is the request."
1777+
<> P.wrap "Here is the request:"
17781778
<> P.newline
17791779
<> P.newline
17801780
<> P.indentN 2 (P.pshown request)
17811781
<> P.newline
17821782
<> P.newline
1783-
<> P.wrap "Here is the full response."
1783+
<> P.wrap "Here is the full response:"
17841784
<> P.newline
17851785
<> P.newline
17861786
<> P.indentN 2 (P.pshown response)
@@ -2362,21 +2362,25 @@ prettyTransportError = \case
23622362
Share.RateLimitExceeded -> "Rate limit exceeded, please try again later."
23632363
Share.Timeout -> "The code server timed-out when responding to your request. Please try again later or report an issue if the problem persists."
23642364
Share.UnexpectedResponse resp ->
2365-
(P.lines . catMaybes)
2366-
[ Just
2367-
( "The server sent a "
2368-
<> P.red (P.shown (Http.statusCode (Servant.responseStatusCode resp)))
2369-
<> " that we didn't expect."
2370-
),
2371-
let body = Text.decodeUtf8 (LazyByteString.toStrict (Servant.responseBody resp))
2372-
in if Text.null body then Nothing else Just (P.newline <> "Response body: " <> P.text body),
2373-
responseRequestId resp <&> \responseId -> P.newline <> "Request ID: " <> P.blue (P.text responseId)
2374-
]
2375-
where
2376-
-- Dig the request id out of a response header.
2377-
responseRequestId :: Servant.Response -> Maybe Text
2378-
responseRequestId =
2379-
fmap Text.decodeUtf8 . List.lookup "X-RequestId" . Foldable.toList @Seq . Servant.responseHeaders
2365+
unexpectedServerResponse resp
2366+
2367+
unexpectedServerResponse :: Servant.ResponseF LazyByteString.ByteString -> P.Pretty Unison.Util.ColorText.ColorText
2368+
unexpectedServerResponse resp =
2369+
(P.lines . catMaybes)
2370+
[ Just
2371+
( "The server sent a "
2372+
<> P.red (P.shown (Http.statusCode (Servant.responseStatusCode resp)))
2373+
<> " that we didn't expect."
2374+
),
2375+
let body = Text.decodeUtf8 (LazyByteString.toStrict (Servant.responseBody resp))
2376+
in if Text.null body then Nothing else Just (P.newline <> "Response body: " <> P.text body),
2377+
responseRequestId resp <&> \responseId -> P.newline <> "Request ID: " <> P.blue (P.text responseId)
2378+
]
2379+
2380+
-- | Dig the request id out of a response header.
2381+
responseRequestId :: Servant.Response -> Maybe Text
2382+
responseRequestId =
2383+
fmap Text.decodeUtf8 . List.lookup "X-RequestId" . Foldable.toList @Seq . Servant.responseHeaders
23802384

23812385
prettyEntityType :: Share.EntityType -> Pretty
23822386
prettyEntityType = \case

0 commit comments

Comments
 (0)