Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 16x 16x 16x 16x 16x 16x 16x 5x 5x 11x 11x 11x 1x 1x 1x 1x | /**
* Error Messages - User-friendly error messages by type
*
* Maps error types to human-readable messages with context-specific overrides.
*/
import { ErrorType } from './error-classifier';
export interface ErrorMessages {
title: string;
message: string;
action: string;
}
/**
* Default error messages for each error type
*/
export const errorMessages: Record<ErrorType, ErrorMessages> = {
[ErrorType.NETWORK]: {
title: 'Connection Error',
message: "We couldn't connect to our servers. Please check your internet connection.",
action: 'Try Again',
},
[ErrorType.VALIDATION]: {
title: 'Invalid Input',
message: 'Some of the information provided is invalid. Please check and try again.',
action: 'Fix Errors',
},
[ErrorType.AUTHENTICATION]: {
title: 'Sign In Required',
message: 'You need to sign in to access this page.',
action: 'Sign In',
},
[ErrorType.AUTHORIZATION]: {
title: 'Access Denied',
message: "You don't have permission to access this resource.",
action: 'Go Back',
},
[ErrorType.NOT_FOUND]: {
title: 'Not Found',
message: "We couldn't find what you're looking for.",
action: 'Go Home',
},
[ErrorType.SERVER]: {
title: 'Server Error',
message: "Our servers are experiencing issues. We're working on it.",
action: 'Try Again',
},
[ErrorType.PAYMENT]: {
title: 'Payment Failed',
message: 'Your payment could not be processed. Please try again.',
action: 'Retry Payment',
},
[ErrorType.RATE_LIMIT]: {
title: 'Too Many Requests',
message: "You've made too many requests. Please wait a moment.",
action: 'Wait',
},
[ErrorType.UNKNOWN]: {
title: 'Oops!',
message: 'Something unexpected happened. Please try again.',
action: 'Try Again',
},
};
/**
* Context-specific message overrides
*
* These override the default messages for specific contexts.
*/
export const contextMessages: Record<
string,
Partial<Record<ErrorType, Partial<ErrorMessages>>>
> = {
checkout: {
[ErrorType.SERVER]: {
message: "We couldn't process your order. Your cart has been saved.",
},
[ErrorType.VALIDATION]: {
message: 'Please check your shipping and payment information.',
},
[ErrorType.PAYMENT]: {
title: 'Payment Declined',
message: 'Your card was declined. Please check your details or try a different card.',
},
},
cart: {
[ErrorType.NOT_FOUND]: {
title: 'Product Unavailable',
message: 'This product is no longer available.',
},
[ErrorType.SERVER]: {
message: "We couldn't update your cart. Please try again.",
},
},
account: {
[ErrorType.AUTHENTICATION]: {
title: 'Session Expired',
message: 'Your session has expired. Please sign in again.',
},
[ErrorType.SERVER]: {
message: "We couldn't load your account. Please try again.",
},
},
product: {
[ErrorType.NOT_FOUND]: {
title: 'Product Not Found',
message: 'This product may have been removed or is no longer available.',
},
},
shop: {
[ErrorType.SERVER]: {
message: "We couldn't load the products. Please try again.",
},
},
wishlist: {
[ErrorType.AUTHENTICATION]: {
message: 'Sign in to view your wishlist.',
},
},
admin: {
[ErrorType.AUTHORIZATION]: {
title: 'Admin Access Required',
message: 'You need admin privileges to access this area.',
},
[ErrorType.SERVER]: {
message: 'An error occurred in the admin panel. This has been logged.',
},
},
support: {
[ErrorType.SERVER]: {
message: 'We couldn\'t load support resources. Please email us directly.',
},
},
orders: {
[ErrorType.NOT_FOUND]: {
title: 'Order Not Found',
message: 'This order could not be found or you may not have access to it.',
},
},
};
/**
* Get error message with context-specific overrides
*
* @example
* ```tsx
* const messages = getErrorMessage(ErrorType.PAYMENT, 'checkout');
* console.log(messages.title); // "Payment Declined"
* ```
*/
export function getErrorMessage(
type: ErrorType,
context?: string
): ErrorMessages {
const base = errorMessages[type];
if (context && contextMessages[context]?.[type]) {
return { ...base, ...contextMessages[context][type] };
}
return base;
}
/**
* Get all available context names
*/
export function getContextNames(): string[] {
return Object.keys(contextMessages);
}
|