Task 2-2: Improve Error Message cho lang_key Requirement
Phase: 2 - Validation Priority: Medium Module:
webmarketplaceDepends on: Không có Reference: docs/BountyHunter-Backend/details/feature-nft-management/SPEC.md
Background
GET /api/nft-rental/my-bounty-balls yêu cầu lang_key param nhưng nếu thiếu, throw LANG_KEY_IS_INVALID. Client không biết lý do lỗi nếu không đọc kỹ error code.
Tasks
DI Note:
NftRentalControllerinject service để xử lý logic — không cần thêm injection cho validation. Spring MVC tự injectHttpServletRequest/HttpServletResponsenếu cần.@RequestParam(required = true)và@Parameterlà annotation-based, không cần runtime injection.
File: webmarketplace/controllers/nft_rental/NftRentalController.java
- [ ] Thêm explicit validation với message rõ ràng hơn:
@GetMapping("/my-bounty-balls") public Result<PageModel<NftBountyBallDto>> getMyBountyBalls( @RequestParam(required = true) String langKey, // ... other params ) { if (langKey == null || langKey.isBlank()) { // Nếu Spring không tự throw, validate thủ công throw new BadRequestException("LANG_KEY_IS_REQUIRED", "lang_key parameter is required. Supported values: en, ja, vi"); } // ... } -
Lưu ý:
@RequestParam(required = true)là default — Spring tự throwMissingServletRequestParameterExceptionnếu thiếu. Verify xem global exception handler có handleMissingServletRequestParameterExceptionchưa (grep trongGlobalExceptionHandlerhoặc@ControllerAdvice). -
[ ] Document supported
lang_keyvalues trong Swagger@Parameterannotation:@Parameter( description = "Language key. Supported: en, ja, vi", required = true, schema = @Schema(allowableValues = {"en", "ja", "vi"}) ) @RequestParam String langKey -
[ ] Nếu có
GlobalExceptionHandler: đảm bảoMissingServletRequestParameterExceptiontrả về message user-friendly thay vì raw Spring error
Verification / Acceptance Criteria
- [ ]
GET /api/nft-rental/my-bounty-ballskhông cólang_key→ trả 400 với message rõ ràng (không phải generic error) - [ ] Response body chứa thông tin: param bị thiếu là
lang_keyvà supported values (en,ja,vi) - [ ] Swagger UI hiển thị
lang_keylà required với allowable values - [ ]
GET /api/nft-rental/my-bounty-balls?lang_key=enhoạt động bình thường - [ ]
GET /api/nft-rental/my-bounty-balls?lang_key=invalidtrả error phù hợp (LANG_KEY_IS_INVALID)
Files to Modify
webmarketplace/controllers/nft_rental/NftRentalController.java