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:
2026-10-22 23:29:47 +03:00
parent d287dd3119
commit 2e43f79256
10 changed files with 305 additions and 7 deletions

View File

@@ -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> =