This document describes the comprehensive error handling system implemented to provide users with clear, actionable guidance instead of technical error messages.
The error handling system transforms technical error messages into user-friendly explanations with actionable steps to resolve issues. It consists of:
- Backend Error Message System - Translates technical errors into user-friendly responses
- Frontend Error Handler - Maps API errors to user-friendly messages and suggestions
- Error Display Component - Provides an intuitive UI for displaying errors with expandable suggestions
The backend includes a comprehensive mapping of technical errors to user-friendly messages:
// Example error mapping
'ValidationError': {
userMessage: 'Please check your input and try again.',
getAction: (error) => {
if (error.details && error.details[0]) {
const field = error.details[0].path?.[0] || 'input';
if (issue.includes('required')) {
return `The ${field} field is required. Please provide a valid value.`;
}
}
return 'Please review all fields and ensure they meet the requirements.';
}
}The backend uses custom error classes for better error categorization:
ContractAddressNotSetError- Smart contract not deployedContractDeploymentFailedError- Contract deployment issuesDIDRegistrationFailedError- DID registration problemsDIDUpdateFailedError- DID update failuresCredentialIssuanceFailedError- Credential issuance issuesTransactionFailedError- Stellar transaction failuresAccountNotFoundError- Account doesn't exist
The global error handler now uses formatErrorResponse() to create user-friendly API responses:
const errorResponse = formatErrorResponse(err, req);
res.status(err.status || statusCode).json(errorResponse);The frontend error handler maps API errors to user-friendly information:
const errorInfo = handleApiError(error);
// Returns: { title, message, suggestions, technicalDetails }A reusable component that displays errors with:
- Clear error title and message
- Expandable suggestions with actionable steps
- Technical details in development mode
- Dismissible interface
All frontend components have been updated to use the new error handling:
- CreateDID.js - DID creation errors
- Contracts.js - Contract deployment errors
- Credentials.js - Credential issuance/verification errors
- ResolveDID.js - DID resolution errors
- Account.js - Account information errors
- useWallet.js - Wallet connection errors
- Technical:
ValidationError, Joi validation failures - User Message: "Please check your input and try again."
- Suggestions: Field-specific guidance based on validation rules
- Technical:
ContractAddressNotSet,ContractDeploymentFailed - User Message: "Smart contract is not deployed yet."
- Suggestions: Deploy contract first, check account balance, verify secret key
- Technical:
DIDRegistrationFailed,DIDUpdateFailed - User Message: "Failed to register/update your DID."
- Suggestions: Check ownership, verify format, ensure funds
- Technical:
TransactionFailed, Stellar SDK errors - User Message: "The Stellar transaction failed."
- Suggestions: Check balance, wait and retry, verify network status
- Technical: Network failures, timeouts, CORS
- User Message: "Network connection problem."
- Suggestions: Check internet, refresh page, wait and retry
// Instead of: throw new Error('Contract deployment failed: ' + error.message);
throw new ContractDeploymentFailedError(error.message);try {
const response = await stellarAPI.post('/contracts/register-did', data);
// Handle success
} catch (err) {
const errorInfo = handleApiError(err);
setError(errorInfo);
toast.error(errorInfo.message);
}{error && (
<ErrorDisplay
error={error}
onClose={() => setError(null)}
/>
)}- User-Friendly Messages: Technical errors are translated into plain language
- Actionable Guidance: Users get specific steps to resolve their issues
- Consistent Experience: All errors follow the same format and style
- Development Support: Technical details are still available in development
- Reduced Support Load: Users can self-resolve common issues
{
"success": false,
"error": {
"code": "ValidationError",
"userMessage": "Please check your input and try again.",
"action": "The did field is required. Please provide a valid value.",
"path": "/api/v1/contracts/register-did",
"timestamp": "2024-01-01T12:00:00.000Z",
"technicalError": "ValidationError: \"did\" is required",
"stack": "Error: ValidationError..."
}
}{
title: "Invalid Input",
message: "The did field is required. Please provide a valid value.",
suggestions: [
"Review all required fields",
"Check that all formats are correct",
"Make sure URLs include http:// or https://"
],
technicalDetails: {
code: "ValidationError",
originalMessage: "ValidationError: \"did\" is required"
}
}To test the error handling system:
- Backend Tests: Use the custom error classes in unit tests
- Frontend Tests: Mock API responses with error formats
- Integration Tests: Verify end-to-end error flow from API to UI
- Internationalization: Support for multiple languages
- Error Analytics: Track common errors for improvement
- Smart Suggestions: AI-powered suggestions based on context
- Error Recovery: Automatic retry mechanisms for transient errors
- Import custom error classes from
contractService.js - Replace generic
Errorthrows with specific error classes - Ensure error messages include relevant context
- Import
handleApiErrorandErrorDisplayutilities - Replace direct error message assignment with
handleApiError() - Use
ErrorDisplaycomponent instead of basicAlert
This error handling system significantly improves the user experience by providing clear, actionable guidance instead of confusing technical error messages.