All Downloads are FREE. Search and download functionalities are using the official Maven repository.

pro.chenggang.plugin.springcloud.gateway.response.strategy.NotFoundExceptionHandlerStrategy Maven / Gradle / Ivy

There is a newer version: 2.1.SR2.2.RELEASE
Show newest version
package pro.chenggang.plugin.springcloud.gateway.response.strategy;

import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.gateway.support.NotFoundException;
import org.springframework.http.HttpStatus;
import pro.chenggang.plugin.springcloud.gateway.option.ResponseResult;
import pro.chenggang.plugin.springcloud.gateway.option.SystemResponseInfo;
import pro.chenggang.plugin.springcloud.gateway.response.ExceptionHandlerResult;

/**
 * Not Found Exception Handler Strategy
 * @author chenggang
 * @date 2019/01/29
 */
@Slf4j
public class NotFoundExceptionHandlerStrategy implements ExceptionHandlerStrategy{

    @Override
    public Class getHandleClass() {
        return NotFoundException.class;
    }

    @Override
    public ExceptionHandlerResult handleException(Throwable throwable) {
        ResponseResult responseResult = new ResponseResult<>(SystemResponseInfo.SERVICE_NOT_AVAILABLE,throwable.getMessage());
        String response = JSON.toJSONString(responseResult);
        ExceptionHandlerResult result = new ExceptionHandlerResult(HttpStatus.NOT_FOUND,response);
        log.debug("[NotFoundExceptionHandlerStrategy]Handle Exception:{},Result:{}",throwable.getMessage(),result);
        return result;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy