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

com.gitee.fufu669.config.exception.CacheServerException Maven / Gradle / Ivy

There is a newer version: 6.666.66021
Show newest version
package com.gitee.fufu669.config.exception;


import com.fasterxml.jackson.annotation.JsonProperty;

import lombok.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.text.MessageFormat;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/** @author wangfupeng */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = false)
public class CacheServerException extends RuntimeException {

	private static final long serialVersionUID = 3687466179508097339L;

	private static final Logger logger = LoggerFactory.getLogger(CacheServerExceptionHandler.class);

    private String code;
    private String message;
    private Object data;

    private static Map props = new ConcurrentHashMap<>();

    static {
        Arrays.stream(CacheServerErrorCode.class.getDeclaredFields())
                .forEach(p -> {
                    try {
                        CacheErrorMessage annotation = p.getAnnotation(CacheErrorMessage.class);
                        props.put(String.valueOf(p.get("value")), annotation.value());
                    } catch (Exception e) {
                        logger.info("fail to load error code:  " + p.getName());
                    }
                });
    }

    public CacheServerException(String code, Object... msg) {
        String message = props.get(String.valueOf(code));
        if (msg != null && msg.length > 0) {
        	message = MessageFormat.format(message, msg);
        }
        this.code = code;
        this.message = message;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy