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

io.gitee.huangguiming.Imcode.exception.IMError Maven / Gradle / Ivy

There is a newer version: 1.0.4
Show newest version
package io.gitee.huangguiming.Imcode.exception;

import io.gitee.huangguiming.Imcode.utils.IMGsonBuilder;
import lombok.Builder;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;

@Data
@Builder
public class IMError implements Serializable {

    /**
     * 错误码
     */
    private int ErrorCode;

    /**
     * 请求状态 ok 成功 fall 失败
     * (如果可以翻译为中文,就为中文)
     */
    private String ActionStatus;

    /**
     * 失败原因.
     */
    private String ErrorInfo;

    public static IMError fromJson(String json) {
        final IMError wxError = IMGsonBuilder.create().fromJson(json, IMError.class);
        if (wxError.getErrorCode() == 0) {
            return wxError;
        }

        if (StringUtils.isNotEmpty(wxError.getErrorInfo())) {
            wxError.setErrorInfo(wxError.getErrorInfo());
        }

        String msg = IMErrorCode.findMsgByCode(wxError.getErrorCode());
        if (msg != null) {
            wxError.setErrorInfo(msg);
        }
        return wxError;

    }

    @Override
    public String toString() {

        return  "错误代码:" + this.ErrorCode + ", 错误信息:" + this.ErrorInfo;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy