package cn.sh.stc.sict.cloud.common.security.component;

import cn.sh.stc.sict.cloud.common.core.constant.Constant;
import cn.sh.stc.sict.cloud.common.security.exception.SictAuth2Exception;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import lombok.SneakyThrows;

/**
 * @Description
 * @Author
 * @Date
 */
public class SictAuth2ExceptionSerializer extends StdSerializer<SictAuth2Exception> {

    public SictAuth2ExceptionSerializer() {
        super(SictAuth2Exception.class);
    }

    @Override
    @SneakyThrows
    public void serialize(SictAuth2Exception value, JsonGenerator gen, SerializerProvider provider) {
        gen.writeStartObject();
        gen.writeObjectField("code", Constant.BYTE_NO);
        gen.writeStringField("msg", value.getMessage());
        gen.writeStringField("data", value.getErrorCode());
        gen.writeEndObject();
    }
}
