Skip to content

Commit 4403d67

Browse files
committed
style(api): add error handling strategy documentation
- Add comprehensive error handling guidelines as comments in the data route file - Explain the strategy for propagating exceptions and handling errors consistently - Clarify the role of the centralized error handler middleware - Provide guidance on when to use local try-catch blocks
1 parent 754f7f1 commit 4403d67

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

routes/api/v1/data/index.dart

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,24 @@
33

44
import 'dart:io';
55

6+
// --- Error Handling Strategy ---
7+
// Route-specific handlers (_handleGet, _handlePost, etc.) should generally
8+
// allow HtHttpExceptions (like NotFoundException, BadRequestException)
9+
// and FormatExceptions thrown by lower layers (Repositories, Clients, JSON parsing)
10+
// to propagate upwards.
11+
//
12+
// These specific exceptions are caught and re-thrown by the main `onRequest`
13+
// handler in this file.
14+
//
15+
// The centralized `errorHandler` middleware (defined in lib/src/middlewares/)
16+
// is responsible for catching these re-thrown exceptions and mapping them to
17+
// appropriate, standardized JSON error responses (e.g., 400, 404, 500).
18+
//
19+
// Local try-catch blocks within specific _handle* methods should be reserved
20+
// for handling errors that require immediate, localized responses (like the
21+
// TypeError during deserialization in _handlePost) or for logging specific
22+
// context before allowing propagation.
23+
624
import 'package:dart_frog/dart_frog.dart';
725
// Import RequestId from the middleware file where it's defined
826
import 'package:ht_api/src/registry/model_registry.dart';

0 commit comments

Comments
 (0)