Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Improve invalid hostname error message

Steven Tey573eff52f7da
diff --git a/apps/web/lib/api/links/process-link.ts b/apps/web/lib/api/links/process-link.ts
index 55e76e4d26..45098fd3b2 100644
--- a/apps/web/lib/api/links/process-link.ts
+++ b/apps/web/lib/api/links/process-link.ts
@@ -175,8 +175,8 @@ export async function processLink<T extends Record<string, any>>({
if (allowedHostnames && !allowedHostnames.includes(urlDomain)) {
return {
link: payload,
- error: `Invalid url. You can only use ${domain} short links for URLs starting with ${allowedHostnames
- .map((d) => `\`${d}\``)
+ error: `Invalid URL. You can only use ${domain} short links for URLs starting with ${allowedHostnames
+ .map((d) => `"${d}"`)
.join(", ")}.`,
code: "unprocessable_entity",
};
diff --git a/apps/web/tests/links/bulk-update-link.test.ts b/apps/web/tests/links/bulk-update-link.test.ts
index 18157943ce..673e3e6bb7 100644
--- a/apps/web/tests/links/bulk-update-link.test.ts
+++ b/apps/web/tests/links/bulk-update-link.test.ts
@@ -89,8 +89,7 @@ test("PATCH /links/bulk", async (ctx) => {
// third link will throw an error because git.new only allows certain destination URLs
expect(links[2]).toStrictEqual({
- error:
- "Invalid url. You can only use git.new short links for URLs starting with `github.com`, `gist.github.com`.",
+ error: `Invalid URL. You can only use git.new short links for URLs starting with "github.com", "gist.github.com".`,
code: "unprocessable_entity",
link: expect.any(Object),
});
diff --git a/apps/web/ui/modals/add-edit-link-modal/index.tsx b/apps/web/ui/modals/add-edit-link-modal/index.tsx
index c8cd2db922..87b0f46de1 100644
--- a/apps/web/ui/modals/add-edit-link-modal/index.tsx
+++ b/apps/web/ui/modals/add-edit-link-modal/index.tsx
@@ -503,15 +503,9 @@ function AddEditLinkModal({
/>
)}
</div>
- {urlError ? (
- <p className="text-sm text-red-600" id="key-error">
- Invalid URL
- </p>
- ) : url ? (
- <div className="animate-text-appear text-xs font-normal text-gray-500">
- press <strong>Enter</strong> ↵ to submit
- </div>
- ) : null}
+ <div className="animate-text-appear text-xs font-normal text-gray-500">
+ press <strong>Enter</strong> ↵ to submit
+ </div>
</div>
<div className="relative mt-2 flex rounded-md shadow-sm">
<input
@@ -546,6 +540,11 @@ function AddEditLinkModal({
</div>
)}
</div>
+ {urlError && (
+ <p className="mt-2 text-sm text-red-600" id="key-error">
+ {urlError}
+ </p>
+ )}
</div>
{key !== "_root" && (