fix: validate grade input and save modal without reload
- require a score and return a clear message for empty/non-numeric values - handle unreadable API request bodies instead of falling back to a bare 400 - submit the grade modal via fetch, show errors in place and update the cell - keep the page scroll position; restore the form feedback tests
This commit is contained in:
@@ -2,6 +2,7 @@ package ru.ysu.lms.common
|
||||
|
||||
import org.springframework.dao.DataIntegrityViolationException
|
||||
import org.springframework.http.ResponseEntity
|
||||
import org.springframework.http.converter.HttpMessageNotReadableException
|
||||
import org.springframework.web.bind.MethodArgumentNotValidException
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice
|
||||
@@ -48,6 +49,20 @@ class LmsExceptionHandler {
|
||||
),
|
||||
)
|
||||
|
||||
/**
|
||||
* Тело запроса не удалось разобрать: пустая строка вместо числа, битый JSON и т.п.
|
||||
* Без этого обработчика клиент получал стандартный ответ Spring без detail.
|
||||
*/
|
||||
@ExceptionHandler(HttpMessageNotReadableException::class)
|
||||
fun handleNotReadable(): ResponseEntity<ApiError> =
|
||||
ResponseEntity.badRequest().body(
|
||||
ApiError(
|
||||
title = "Bad Request",
|
||||
status = 400,
|
||||
detail = "Проверьте формат введённых данных",
|
||||
),
|
||||
)
|
||||
|
||||
/** Нарушение уникальности/ссылок (гонки двойной отправки) — конфликт, а не 500. */
|
||||
@ExceptionHandler(DataIntegrityViolationException::class)
|
||||
fun handleDataIntegrity(): ResponseEntity<ApiError> =
|
||||
|
||||
Reference in New Issue
Block a user