From 1c998ab99feb780f6183bcb7bd518eb3f2d77736 Mon Sep 17 00:00:00 2001 From: enes Date: Wed, 28 Aug 2024 09:32:23 +0200 Subject: [PATCH] refactor(error): refactor MetaParseError 2 --- src/types/errors/MetaParseError.ts | 6 ++++++ src/utils/meta.ts | 15 ++++++--------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/types/errors/MetaParseError.ts b/src/types/errors/MetaParseError.ts index 85cddec..96adab5 100644 --- a/src/types/errors/MetaParseError.ts +++ b/src/types/errors/MetaParseError.ts @@ -1,5 +1,11 @@ import { Jsonable } from '.' +// Reuse common error messages for meta parsing +export enum MetaParseErrorType { + 'PARSE_ERROR_EVENT' = 'error occurred in parsing the create signature event', + 'PARSE_ERROR_SIGNATURE_EVENT_CONTENT' = "err in parsing the createSignature event's content" +} + export class MetaParseError extends Error { public readonly context?: Jsonable diff --git a/src/utils/meta.ts b/src/utils/meta.ts index 62eb740..c915f66 100644 --- a/src/utils/meta.ts +++ b/src/utils/meta.ts @@ -4,7 +4,10 @@ import { Event, verifyEvent } from 'nostr-tools' import { toast } from 'react-toastify' import { extractFileExtensions } from './file' import { handleError } from '../types/errors' -import { MetaParseError } from '../types/errors/MetaParseError' +import { + MetaParseError, + MetaParseErrorType +} from '../types/errors/MetaParseError' export enum SignStatus { Signed = 'Signed', @@ -19,12 +22,6 @@ export enum SigitStatus { Complete = 'Completed' } -// Reuse common error messages for meta parsing -export enum SigitMetaParseErrorType { - 'PARSE_ERROR_EVENT' = 'error occurred in parsing the create signature event', - 'PARSE_ERROR_SIGNATURE_EVENT_CONTENT' = "err in parsing the createSignature event's content" -} - export interface SigitCardDisplayInfo { createdAt?: number title?: string @@ -45,7 +42,7 @@ export const parseNostrEvent = async (raw: string): Promise => { const event = await parseJson(raw) return event } catch (error) { - throw new MetaParseError(SigitMetaParseErrorType.PARSE_ERROR_EVENT, { + throw new MetaParseError(MetaParseErrorType.PARSE_ERROR_EVENT, { cause: handleError(error), context: raw }) @@ -66,7 +63,7 @@ export const parseCreateSignatureEventContent = async ( return createSignatureEventContent } catch (error) { throw new MetaParseError( - SigitMetaParseErrorType.PARSE_ERROR_SIGNATURE_EVENT_CONTENT, + MetaParseErrorType.PARSE_ERROR_SIGNATURE_EVENT_CONTENT, { cause: handleError(error), context: raw