This commit is contained in:
2026-10-17 08:59:12 +03:00
parent 95aed3c25b
commit 7ffebe65d0
52 changed files with 1315 additions and 204 deletions
@@ -36,10 +36,12 @@ public class GlobalExceptionHandler {
@ExceptionHandler(UnauthorizedException.class)
public ResponseEntity<ErrorDTO> unauthorized(UnauthorizedException e, HttpServletRequest req) {
String scheme = req.getRequestURI().equals("/api/v1/auth/sessions")
? "Basic" : "Bearer";
boolean isLogin = "/api/v1/auth/sessions".equals(req.getRequestURI());
String challenge = isLogin
? "Basic realm=\"messenger\", charset=\"UTF-8\""
: "Bearer realm=\"messenger\"";
return ResponseEntity.status(HttpStatus.UNAUTHORIZED)
.header("WWW-Authenticate", scheme + " realm=\"messenger\"")
.header("WWW-Authenticate", challenge)
.body(errors.error(ErrorErrorDTO.CodeEnum.UNAUTHORIZED, e.getMessage(), req));
}