DEV Community

iron_man
iron_man

Posted on

ApiErrors.java

package com.hardening;

import java.util.Map;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestControllerAdvice
public class ApiErrors {
@ExceptionHandler(IllegalArgumentException.class)
public ResponseEntity<?> invalid(IllegalArgumentException e) { return ResponseEntity.badRequest().body(Map.of("code","VALIDATION","message",e.getMessage())); }
@ExceptionHandler(Exception.class)
public ResponseEntity<?> failure(Exception e) { return ResponseEntity.internalServerError().body(Map.of("code","OPERATION_FAILED","message","Operation could not complete. Check server configuration and run history.")); }
}

Top comments (0)