diff --git a/packages/backend/src/database.ts b/packages/backend/src/database.ts index e973f61a..82a79f21 100644 --- a/packages/backend/src/database.ts +++ b/packages/backend/src/database.ts @@ -661,7 +661,7 @@ export class Database { }); if (deployment === null) { - throw new Error(`Error finding DNS data for project with id ${projectId}`); + throw new Error(`DNS deployment not found for project ${projectId}`); } return deployment.dnsRecordData; diff --git a/packages/backend/src/registry.ts b/packages/backend/src/registry.ts index 96b52066..8d43c969 100644 --- a/packages/backend/src/registry.ts +++ b/packages/backend/src/registry.ts @@ -16,7 +16,7 @@ import { ApplicationDeploymentRequest, ApplicationDeploymentRemovalRequest } from './entity/Deployment'; -import { AppDeploymentRecord, AppDeploymentRemovalRecord, AuctionParams, DeployerRecord, DNSRecord } from './types'; +import { AppDeploymentRecord, AppDeploymentRemovalRecord, AuctionParams, DeployerRecord, DNSRecord, RegistryRecord } from './types'; import { getConfig, getRepoDetails, registryTransactionWithRetry, sleep } from './utils'; const log = debug('snowball:registry'); @@ -444,8 +444,13 @@ export class Registry { /** * Fetch record by Id */ - async getRecordById(id: string): Promise { - return this.registry.getRecordsByIds([id]); + async getRecordById(id: string): Promise { + const record = await this.registry.getRecordsByIds([id]); + if (record.length === 0) { + return null; + } + + return record[0]; } async createApplicationDeploymentRemovalRequest(data: { diff --git a/packages/backend/src/service.ts b/packages/backend/src/service.ts index 14e1162f..98bd9d96 100644 --- a/packages/backend/src/service.ts +++ b/packages/backend/src/service.ts @@ -203,7 +203,14 @@ export class Service { return; } - const dnsRecord: DNSRecord = (await this.laconicRegistry.getRecordById(record.attributes.dns))[0]; + const registryRecord = await this.laconicRegistry.getRecordById(record.attributes.dns); + + if (!registryRecord) { + log(`DNS record not found for deployment ${deployment.id}`); + return; + } + + const dnsRecord = registryRecord as DNSRecord; const dnsRecordData: DNSRecordAttributes = { name: dnsRecord.attributes.name, diff --git a/packages/backend/src/types.ts b/packages/backend/src/types.ts index 91654576..89ba3de4 100644 --- a/packages/backend/src/types.ts +++ b/packages/backend/src/types.ts @@ -55,7 +55,7 @@ export interface AppDeploymentRemovalRecordAttributes { version: string; } -interface RegistryRecord { +export interface RegistryRecord { id: string; names: string[] | null; owners: string[];