Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions apps/web/lib/api/domains/claim-dot-link-domain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,6 @@ export async function claimDotLinkDomain({
}),
]);

// if for some reason the domain is already registered, we should fail
if (response.RegisterResponse.Error) {
throw new DubApiError({
code: "forbidden",
message: response.RegisterResponse.Error,
});
}

// if the domain was added to a different workspace but is not verified
// we should remove it to free up the domain for the current workspace
if (matchingUnverifiedDomain) {
Expand Down
26 changes: 23 additions & 3 deletions apps/web/lib/dynadot/register-domain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@ import z from "@/lib/zod";
import { DubApiError } from "../api/errors";
import { DYNADOT_API_KEY, DYNADOT_BASE_URL, DYNADOT_COUPON } from "./constants";

/*
Possible statuses:
success
error
not_available
insufficient_funds
over_quota – When Dynadot's system detects an unusually high number of registration calls within a specific timeframe. This is a rare occurrence and typically not triggered under normal conditions.
order_pending_process –  means the order was created for the command, however there is something need additional investigation, and our team will step in later on to process the order accordingtly.
system_busy – normally means the system/connection is currently busy, you may retry command after a period of time
*/

const schema = z.object({
RegisterResponse: z.object({
Status: z.string(),
Expand Down Expand Up @@ -39,11 +50,20 @@ export const registerDomain = async ({ domain }: { domain: string }) => {

const data = schema.parse(await response.json());

if (data.RegisterResponse.Status !== "success")
const { Status, Error } = data.RegisterResponse;

const errorCodes = {
error: Error,
not_available: "Domain not available.",
system_busy: "System is busy. Please try again.",
};

if (Status !== "success") {
throw new DubApiError({
code: "forbidden",
message: `Failed to register domain: ${data.RegisterResponse.Error}`,
code: "bad_request",
message: `Failed to register domain: ${errorCodes[Status] || "Please try again."}`,
});
}

return data;
};
Loading