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.

Handle Dyandot DNS configuration errors

Tim Wilsoncc905e2051be
diff --git a/apps/web/lib/dynadot/configure-dns.ts b/apps/web/lib/dynadot/configure-dns.ts
index e6f48b7645..bd9b5fa76c 100644
--- a/apps/web/lib/dynadot/configure-dns.ts
+++ b/apps/web/lib/dynadot/configure-dns.ts
@@ -1,5 +1,15 @@
+import { z } from "zod";
+import { DubApiError } from "../api/errors";
import { DYNADOT_API_KEY, DYNADOT_BASE_URL } from "./constants";
+const schema = z.object({
+ SetDnsResponse: z.object({
+ ResponseCode: z.string().or(z.number()),
+ Status: z.string(),
+ Error: z.string().optional(),
+ }),
+});
+
export const configureDNS = async ({ domain }: { domain: string }) => {
const searchParams = new URLSearchParams({
key: DYNADOT_API_KEY,
@@ -9,9 +19,32 @@ export const configureDNS = async ({ domain }: { domain: string }) => {
main_record0: "76.76.21.21",
});
- return fetch(`${DYNADOT_BASE_URL}?${searchParams.toString()}`, {
- headers: {
- "Content-Type": "application/x-www-form-urlencoded",
+ const response = await fetch(
+ `${DYNADOT_BASE_URL}?${searchParams.toString()}`,
+ {
+ headers: {
+ "Content-Type": "application/x-www-form-urlencoded",
+ },
},
- }).then((res) => res.json());
+ );
+
+ if (!response.ok) {
+ throw new DubApiError({
+ code: "bad_request",
+ message: `Failed to configure DNS for domain "${domain}": ${response.statusText}`,
+ });
+ }
+
+ const data = schema.parse(await response.json());
+
+ const { Status, Error } = data.SetDnsResponse;
+
+ if (Status !== "success") {
+ throw new DubApiError({
+ code: "bad_request",
+ message: `Failed to configure DNS for domain "${domain}": ${Error}`,
+ });
+ }
+
+ return data;
};