Adds robust error handling for API interactions
Introduces a comprehensive custom error hierarchy for more precise error management in API calls Replaces generic error throwing with specific error types: - Adds custom error classes for various API-related scenarios - Improves error handling in cleanup and API client components - Enables more informative and type-safe error tracking Enhances error reporting and debugging capabilities for Anthropic API interactions
This commit is contained in:
4 files changed
+109
-26
No files matched your search
+10
-11
@@ -4,6 +4,7 @@
|
||||
import { Editor, MarkdownView, Notice } from 'obsidian';
|
||||
import { CleanupService } from '../services/cleanupService';
|
||||
import { FreewritingCleanupSettings, ANTHROPIC_LIMITS } from '../types';
|
||||
import { ApiKeyError, TextTooLongError, ServiceUnavailableError } from '../errors';
|
||||
|
||||
/**
|
||||
* Command handler for freewriting cleanup operations
|
||||
@@ -72,17 +73,15 @@ export class CleanupCommand {
|
||||
editor.setCursor(insertPosition);
|
||||
editor.replaceRange(formattedResult, insertPosition);
|
||||
} catch (error) {
|
||||
// Handle specific error types
|
||||
if (error instanceof Error) {
|
||||
if (error.message.includes('API key')) {
|
||||
new Notice('API key error. Please check your settings.');
|
||||
} else if (error.message.includes('too long')) {
|
||||
new Notice('Text is too long for processing.');
|
||||
} else if (error.message.includes('Failed after')) {
|
||||
new Notice('Service temporarily unavailable. Please try again.');
|
||||
} else {
|
||||
new Notice(`Cleanup failed: ${error.message}`);
|
||||
}
|
||||
// Handle specific error types using instanceof checks
|
||||
if (error instanceof ApiKeyError) {
|
||||
new Notice('API key error. Please check your settings.');
|
||||
} else if (error instanceof TextTooLongError) {
|
||||
new Notice('Text is too long for processing.');
|
||||
} else if (error instanceof ServiceUnavailableError) {
|
||||
new Notice('Service temporarily unavailable. Please try again.');
|
||||
} else if (error instanceof Error) {
|
||||
new Notice(`Cleanup failed: ${error.message}`);
|
||||
} else {
|
||||
new Notice('An unexpected error occurred during cleanup.');
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user