Skip to content

Commit 87734ad

Browse files
committed
feat: Improved consistency for http status (#2001)
1 parent 77f4a90 commit 87734ad

File tree

1 file changed

+35
-33
lines changed
  • packages/react-email/src/components/toolbar

1 file changed

+35
-33
lines changed

packages/react-email/src/components/toolbar/linter.tsx

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,22 @@ export const Linter = ({ rows }: LinterProps) => {
9292
const failingCheck = row.result.checks.find(
9393
(check) => check.passed === false,
9494
)!;
95+
const metadata: React.ReactNode[] = [];
96+
for (const check of row.result.checks) {
97+
if (
98+
check.type === 'fetch_attempt' &&
99+
check.metadata.fetchStatusCode
100+
) {
101+
metadata.push(<>HTTP {check.metadata.fetchStatusCode}</>);
102+
}
103+
}
104+
metadata.push(
105+
<CodePreviewLineLink
106+
line={row.result.codeLocation.line}
107+
column={row.result.codeLocation.column}
108+
type="html"
109+
/>,
110+
);
95111
return (
96112
<Result status={row.result.status} key={i}>
97113
<Result.Name>{sanitize(failingCheck.type)}</Result.Name>
@@ -102,20 +118,14 @@ export const Linter = ({ rows }: LinterProps) => {
102118
{failingCheck.type === 'fetch_attempt' &&
103119
failingCheck.metadata.fetchStatusCode &&
104120
failingCheck.metadata.fetchStatusCode >= 300 &&
105-
failingCheck.metadata.fetchStatusCode < 400 ? (
106-
<>
107-
<strong>{failingCheck.metadata.fetchStatusCode}</strong>:
108-
There was a redirect, the content may have been moved
109-
</>
110-
) : null}
121+
failingCheck.metadata.fetchStatusCode < 400
122+
? 'There was a redirect, the content may have been moved'
123+
: null}
111124
{failingCheck.type === 'fetch_attempt' &&
112125
failingCheck.metadata.fetchStatusCode &&
113-
failingCheck.metadata.fetchStatusCode >= 400 ? (
114-
<>
115-
<strong>{failingCheck.metadata.fetchStatusCode}</strong>:
116-
The link is broken
117-
</>
118-
) : null}
126+
failingCheck.metadata.fetchStatusCode >= 400
127+
? 'The link is broken'
128+
: null}
119129
{failingCheck.type === 'syntax'
120130
? 'The link is broken due to invalid syntax'
121131
: null}
@@ -124,15 +134,7 @@ export const Linter = ({ rows }: LinterProps) => {
124134
{row.result.link}
125135
</span>
126136
</Result.Description>
127-
<Result.Metadata>
128-
{[
129-
<CodePreviewLineLink
130-
line={row.result.codeLocation.line}
131-
column={row.result.codeLocation.column}
132-
type="html"
133-
/>,
134-
]}
135-
</Result.Metadata>
137+
<Result.Metadata>{metadata}</Result.Metadata>
136138
</Result>
137139
);
138140
}
@@ -146,6 +148,12 @@ export const Linter = ({ rows }: LinterProps) => {
146148
if (check.type === 'image_size' && check.metadata.byteCount) {
147149
metadata.push(prettyBytes(check.metadata.byteCount));
148150
}
151+
if (
152+
check.type === 'fetch_attempt' &&
153+
check.metadata.fetchStatusCode
154+
) {
155+
metadata.push(<>HTTP {check.metadata.fetchStatusCode}</>);
156+
}
149157
}
150158
metadata.push(
151159
<CodePreviewLineLink
@@ -164,20 +172,14 @@ export const Linter = ({ rows }: LinterProps) => {
164172
{failingCheck.type === 'fetch_attempt' &&
165173
failingCheck.metadata.fetchStatusCode &&
166174
failingCheck.metadata.fetchStatusCode >= 300 &&
167-
failingCheck.metadata.fetchStatusCode < 400 ? (
168-
<>
169-
<strong>{failingCheck.metadata.fetchStatusCode}</strong>:
170-
There was a redirect, the image may have been moved
171-
</>
172-
) : null}
175+
failingCheck.metadata.fetchStatusCode < 400
176+
? 'There was a redirect, the image may have been moved'
177+
: null}
173178
{failingCheck.type === 'fetch_attempt' &&
174179
failingCheck.metadata.fetchStatusCode &&
175-
failingCheck.metadata.fetchStatusCode >= 400 ? (
176-
<>
177-
<strong>{failingCheck.metadata.fetchStatusCode}</strong>:
178-
The image is broken
179-
</>
180-
) : null}
180+
failingCheck.metadata.fetchStatusCode >= 400
181+
? 'The image is broken'
182+
: null}
181183
{failingCheck.type === 'syntax'
182184
? 'The image is broken due to an invalid source'
183185
: null}

0 commit comments

Comments
 (0)