Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Feature document database migration #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
fulleni merged 23 commits into main from feature_document_database_migration
Jul 12, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
49d1e91
feat(auth): create ownership check middleware
fulleni Jul 11, 2025
ea709e9
feat(auth): apply ownership check middleware to item routes
fulleni Jul 11, 2025
cc9d32f
refactor(api): adapt GET /data to use native document query
fulleni Jul 11, 2025
34a0029
refactor(api): adapt GET /data to use native document query
fulleni Jul 11, 2025
c065be4
feat(db): replace postgres seeding service with mongodb
fulleni Jul 11, 2025
fe51a1e
feat(db): replace postgres seeding service with mongodb
fulleni Jul 11, 2025
1bca9ab
refactor(deps): remove postgres dependencies
fulleni Jul 11, 2025
bfb3e5f
feat(db): migrate dependency injection to mongodb
fulleni Jul 11, 2025
bf6f59d
docs: update readme for mongodb migration
fulleni Jul 11, 2025
c6877bc
refactor(auth): use readAll with filter in AuthService
fulleni Jul 11, 2025
38853ea
docs: update .env.example for mongodb connection string
fulleni Jul 11, 2025
b07d6d2
fix(config): make .env file loading robust
fulleni Jul 11, 2025
7b24b53
/// issues where the execution context's working directory is not the
fulleni Jul 11, 2025
20a92d2
fix(config): correct directory traversal in .env search
fulleni Jul 11, 2025
96912c2
feat(config): enhance .env loading logs
fulleni Jul 11, 2025
e7d0d8d
fix(config): prevent state corruption on failed dependency init
fulleni Jul 11, 2025
d1ac01a
fix(config): make dependency init robust against all throwables
fulleni Jul 11, 2025
6e84bcf
chore
fulleni Jul 11, 2025
4ce3cc5
fix(api): make database seeding idempotent and preserve IDs
fulleni Jul 12, 2025
5207475
fix(api): ensure all user data is deleted on account deletion
fulleni Jul 12, 2025
dbae817
refactor(api): use repository count method for dashboard summary
fulleni Jul 12, 2025
c49d2c4
fix(api): improve error handling for invalid JSON body
fulleni Jul 12, 2025
b2b4363
fix(api): correct admin data scoping in generic data handlers
fulleni Jul 12, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix(api): improve error handling for invalid JSON body
Adds a specific error handler for `CheckedFromJsonException` to return a
400 Bad Request instead of a generic 500 Internal Server Error when
deserialization fails due to invalid client input.
This provides more accurate feedback to API clients when they send a
request body that is missing required fields or contains incorrect
data types.
  • Loading branch information
fulleni committed Jul 12, 2025
commit c49d2c46cbf988ded19679f40f9d2ffe91f850a7
16 changes: 16 additions & 0 deletions lib/src/middlewares/error_handler.dart
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'dart:io';

import 'package:dart_frog/dart_frog.dart';
import 'package:ht_shared/ht_shared.dart';
import 'package:json_annotation/json_annotation.dart';

/// Middleware that catches errors and converts them into
/// standardized JSON responses.
Expand All @@ -26,6 +27,21 @@ Middleware errorHandler() {
'error': {'code': errorCode, 'message': e.message},
},
);
} on CheckedFromJsonException catch (e, stackTrace) {
// Handle json_serializable validation errors. These are client errors.
final field = e.key ?? 'unknown';
final message = 'Invalid request body: Field "$field" has an '
'invalid value or is missing. ${e.message}';
print('CheckedFromJsonException Caught: $e\n$stackTrace');
return Response.json(
statusCode: HttpStatus.badRequest, // 400
body: {
'error': {
'code': 'invalidField',
'message': message,
},
},
);
} on FormatException catch (e, stackTrace) {
// Handle data format/parsing errors (often indicates bad client input)
print('FormatException Caught: $e\n$stackTrace'); // Log for debugging
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ dependencies:
ht_shared:
git:
url: https://github.com/headlines-toolkit/ht-shared.git

json_annotation: ^4.9.0
logging: ^1.3.0
meta: ^1.16.0
mongo_dart: ^0.10.5
Expand Down

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /