mirror of
https://github.com/neynarxyz/create-farcaster-mini-app.git
synced 2025-12-06 09:22:32 -05:00
formatting
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
import { type ReactElement } from "react";
|
||||
import { BaseError, UserRejectedRequestError } from "viem";
|
||||
import { type ReactElement } from 'react';
|
||||
import { BaseError, UserRejectedRequestError } from 'viem';
|
||||
|
||||
/**
|
||||
* Renders an error object in a user-friendly format.
|
||||
*
|
||||
*
|
||||
* This utility function takes an error object and renders it as a React element
|
||||
* with consistent styling. It handles different types of errors including:
|
||||
* - Error objects with message properties
|
||||
@@ -11,14 +11,14 @@ import { BaseError, UserRejectedRequestError } from "viem";
|
||||
* - String errors
|
||||
* - Unknown error types
|
||||
* - User rejection errors (special handling for wallet rejections)
|
||||
*
|
||||
*
|
||||
* The rendered error is displayed in a gray container with monospace font
|
||||
* for better readability of technical error details. User rejections are
|
||||
* displayed with a simpler, more user-friendly message.
|
||||
*
|
||||
*
|
||||
* @param error - The error object to render
|
||||
* @returns ReactElement - A styled error display component, or null if no error
|
||||
*
|
||||
*
|
||||
* @example
|
||||
* ```tsx
|
||||
* {isError && renderError(error)}
|
||||
@@ -27,11 +27,11 @@ import { BaseError, UserRejectedRequestError } from "viem";
|
||||
export function renderError(error: unknown): ReactElement | null {
|
||||
// Handle null/undefined errors
|
||||
if (!error) return null;
|
||||
|
||||
|
||||
// Special handling for user rejections in wallet operations
|
||||
if (error instanceof BaseError) {
|
||||
const isUserRejection = error.walk(
|
||||
(e) => e instanceof UserRejectedRequestError
|
||||
e => e instanceof UserRejectedRequestError
|
||||
);
|
||||
|
||||
if (isUserRejection) {
|
||||
@@ -43,10 +43,10 @@ export function renderError(error: unknown): ReactElement | null {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Extract error message from different error types
|
||||
let errorMessage: string;
|
||||
|
||||
|
||||
if (error instanceof Error) {
|
||||
errorMessage = error.message;
|
||||
} else if (typeof error === 'object' && error !== null && 'error' in error) {
|
||||
@@ -63,4 +63,4 @@ export function renderError(error: unknown): ReactElement | null {
|
||||
<div className="whitespace-pre-wrap break-words">{errorMessage}</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user