package com.qmth.boot.api.exception;

import com.qmth.boot.api.annotation.Aac;
import com.qmth.boot.api.constant.ApiConstant;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.boot.web.servlet.error.ErrorController;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@ConditionalOnExpression("${" + ApiConstant.CONFIG_PREFIX + ".error-mapping:true}")
@Aac(strict = false, auth = false)
public class DefaultErrorController implements ErrorController, ApiConstant {

    private static ExceptionResponseEntity entity = new ExceptionResponseEntity(HttpStatus.NOT_FOUND.value(),
            "request url not found", null);

    @Override
    public String getErrorPath() {
        return DEFAULT_ERROR_URI;
    }

    @RequestMapping(DEFAULT_ERROR_URI)
    public ExceptionResponseEntity error() {
        return entity;
    }

}
