Skip to content

Commit 9efd57e

Browse files
committed
Add error for missing parmeters
1 parent 3cae5bd commit 9efd57e

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

endpoints/min-browser-version-for-feature.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@ export function minBrowserVersion(context: Context) {
99

1010
const { features, filter } = context.req.queries();
1111
if (!features || features.length === 0) {
12-
return context.body(
13-
"Feature parameter is required. Please provide at least one feature to check. Example: ?features=AbortController",
14-
400,
15-
{ "Content-Type": "text/plain" },
12+
throw new Error(
13+
"No features provided. Please provide at least one feature to check the minimum browser version.",
1614
);
1715
}
1816

main.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,30 @@ app.onError((err, c) => {
3636
);
3737
});
3838

39+
app.notFound((c) => {
40+
return c.body(
41+
RenderError({
42+
error:
43+
"The requested resource was not found. use /min-browser-version to get a badge for a specific feature.",
44+
}),
45+
404,
46+
{ "Content-Type": "image/svg+xml" },
47+
);
48+
});
49+
3950
app.get("/all-features", listAllFeatures);
4051
app.get("/min-browser-version", minBrowserVersion);
4152
app.get("/", (c) => {
42-
return c.text("Welcome to the Can I Use Embed API. Use /all-features to get a list of all features.");
53+
return c.text(
54+
`Welcome to the Can I Use Embed API.
55+
Use /all-features to get a list of all features.
56+
Use /min-browser-version?features=FEATURE_NAME&filter=FILTER_NAME to get the minimum browser version for a specific feature.
57+
Example: /min-browser-version?features=api:navigator:serviceworker&filter=chrome
58+
59+
for documentation visit: https://github.com/K0IN/can-i-use-embed`,
60+
200,
61+
{ "Content-Type": "text/plain" },
62+
);
4363
});
4464

4565
Deno.serve({

rendering/test-renders.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ if (import.meta.main) {
4040
{
4141
const svgString = RenderError({
4242
error: "Loading the data failed and now im here thanks test 123.",
43-
tooltip: "This is a tooltip",
4443
});
4544
await Deno.writeFile(
4645
path.join(import.meta.dirname ?? "", "RenderError.svg"),

0 commit comments

Comments
 (0)