Skip to content

Commit 503039f

Browse files
committed
fix: display trial errors in the dashboard
The error was essentially being ignored before!
1 parent 3a1fa04 commit 503039f

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

enterprise/trialer/trialer.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,22 @@ func New(db database.Store, url string, keys map[string]ed25519.PublicKey) func(
3939
return xerrors.Errorf("perform license request: %w", err)
4040
}
4141
defer res.Body.Close()
42+
if res.StatusCode != http.StatusOK {
43+
body, err := io.ReadAll(res.Body)
44+
if err != nil {
45+
return xerrors.Errorf("read license response: %w", err)
46+
}
47+
// This is the format of the error response from
48+
// the license server.
49+
var msg struct {
50+
Error string `json:"error"`
51+
}
52+
err = json.Unmarshal(body, &msg)
53+
if err != nil {
54+
return xerrors.Errorf("unmarshal error: %w", err)
55+
}
56+
return xerrors.New(msg.Error)
57+
}
4258
raw, err := io.ReadAll(res.Body)
4359
if err != nil {
4460
return xerrors.Errorf("read license: %w", err)

site/src/pages/SetupPage/SetupPageView.stories.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@ export const FormError: Story = {
2222
},
2323
};
2424

25+
export const TrialError: Story = {
26+
args: {
27+
error: mockApiError({
28+
message: "Couldn't generate trial!",
29+
detail: "It looks like your team is already trying Coder.",
30+
}),
31+
},
32+
}
33+
2534
export const Loading: Story = {
2635
args: {
2736
isLoading: true,

site/src/pages/SetupPage/SetupPageView.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import LoadingButton from "@mui/lab/LoadingButton";
2+
import AlertTitle from "@mui/material/AlertTitle";
23
import Autocomplete from "@mui/material/Autocomplete";
34
import Checkbox from "@mui/material/Checkbox";
45
import Link from "@mui/material/Link";
56
import MenuItem from "@mui/material/MenuItem";
67
import TextField from "@mui/material/TextField";
8+
import { isAxiosError } from "axios";
79
import { type FormikContextType, useFormik } from "formik";
810
import type { FC } from "react";
911
import * as Yup from "yup";
1012
import type * as TypesGen from "api/typesGenerated";
13+
import { Alert, AlertDetail } from "components/Alert/Alert";
1114
import { FormFields, VerticalForm } from "components/Form/Form";
1215
import { CoderIcon } from "components/Icons/CoderIcon";
1316
import { SignInLayout } from "components/SignInLayout/SignInLayout";
@@ -316,6 +319,21 @@ export const SetupPageView: FC<SetupPageViewProps> = ({
316319
</>
317320
)}
318321

322+
{isAxiosError(error) && error.response?.data?.message && (
323+
<Alert severity="error">
324+
<AlertTitle>{error.response.data.message}</AlertTitle>
325+
{error.response.data.detail && (
326+
<AlertDetail>
327+
{error.response.data.detail}
328+
<br />
329+
<Link target="_blank" href="https://coder.com/contact/sales">
330+
Contact Sales
331+
</Link>
332+
</AlertDetail>
333+
)}
334+
</Alert>
335+
)}
336+
319337
<LoadingButton
320338
fullWidth
321339
loading={isLoading}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy