package com.eshore.gringotts.web.configuration;

import com.eshore.gringotts.web.configuration.amis.AmisResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 处理错误信息
 *
 * @author lanyuanxiaoyao
 * @date 2024-01-02
 */
@RestControllerAdvice
public class ErrorController {
    private static final Logger logger = LoggerFactory.getLogger(ErrorController.class);

    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    @ExceptionHandler(Throwable.class)
    public AmisResponse<Object> errorHandler(Throwable throwable) {
        logger.error("Error", throwable);
        return AmisResponse.responseError(throwable.getMessage());
    }
}
