Skip to content

Commit

Permalink
fix: add missing custom error
Browse files Browse the repository at this point in the history
  • Loading branch information
dr497 committed May 20, 2024
1 parent c0a6b4e commit 61f2077
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
13 changes: 7 additions & 6 deletions js/src/bindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ import { FavouriteDomain, NAME_OFFERS_ID } from "./favorite-domain";
import {
AccountDoesNotExistError,
InvalidDomainError,
InvalidParrentError,
InvalidSubdomainError,
PythFeedNotFoundError,
UnsupportedRecordError,
Expand Down Expand Up @@ -651,7 +652,7 @@ export const createRecordV2Instruction = (
}

if (!parent) {
throw new Error("Invalid parent");
throw new InvalidParrentError("Parent could not be found");
}

const ix = allocateAndPostRecord(
Expand Down Expand Up @@ -743,7 +744,7 @@ export const updateRecordV2Instruction = (
}

if (!parent) {
throw new Error("Invalid parent");
throw new InvalidParrentError("Parent could not be found");
}

const ix = editRecord(
Expand Down Expand Up @@ -784,7 +785,7 @@ export const deleteRecordV2 = (
}

if (!parent) {
throw new Error("Invalid parent");
throw new InvalidParrentError("Parent could not be found");
}

const ix = deleteRecord(
Expand Down Expand Up @@ -816,7 +817,7 @@ export const validateRecordV2Content = (
}

if (!parent) {
throw new Error("Invalid parent");
throw new InvalidParrentError("Parent could not be found");
}

const ix = validateSolanaSignature(
Expand Down Expand Up @@ -849,7 +850,7 @@ export const writRoaRecordV2 = (
}

if (!parent) {
throw new Error("Invalid parent");
throw new InvalidParrentError("Parent could not be found");
}
const ix = writeRoa(
payer,
Expand Down Expand Up @@ -881,7 +882,7 @@ export const ethValidateRecordV2Content = (
}

if (!parent) {
throw new Error("Invalid parent");
throw new InvalidParrentError("Parent could not be found");
}

const ix = validateEthSignature(
Expand Down
14 changes: 14 additions & 0 deletions js/src/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ export enum ErrorType {
PythFeedNotFound = "PythFeedNotFound",
InvalidRoA = "InvalidRoA",
InvalidPda = "InvalidPda",
InvalidParrent = "InvalidParrent",
NftRecordNotFound = "NftRecordNotFound",
}

export class SNSError extends Error {
Expand Down Expand Up @@ -237,3 +239,15 @@ export class InvalidPdaError extends SNSError {
super(ErrorType.InvalidPda, message);
}
}

export class InvalidParrentError extends SNSError {
constructor(message?: string) {
super(ErrorType.InvalidParrent, message);
}
}

export class NftRecordNotFoundError extends SNSError {
constructor(message?: string) {
super(ErrorType.NftRecordNotFound, message);
}
}
5 changes: 4 additions & 1 deletion js/src/nft/name-tokenizer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { deserialize } from "borsh";
import { Connection, PublicKey } from "@solana/web3.js";
import { Buffer } from "buffer";
import { NftRecordNotFoundError } from "../error";

export const NAME_TOKENIZER_ID = new PublicKey(
"nftD3vbNkNqfj2Sd3HZwbpw4BxxKWr4AjGb9X38JeZk",
Expand Down Expand Up @@ -61,7 +62,9 @@ export class NftRecord {
static async retrieve(connection: Connection, key: PublicKey) {
const accountInfo = await connection.getAccountInfo(key);
if (!accountInfo || !accountInfo.data) {
throw new Error("NFT record not found");
throw new NftRecordNotFoundError(
"NFT record not found: " + key.toBase58(),
);
}
return this.deserialize(accountInfo.data);
}
Expand Down

0 comments on commit 61f2077

Please sign in to comment.