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

com.aliyun.sdk.gateway.eiam.dev.exception.PopClientException Maven / Gradle / Ivy

The newest version!
package com.aliyun.sdk.gateway.eiam.dev.exception;

import com.aliyun.core.utils.StringUtils;
import darabonba.core.exception.ClientException;
import darabonba.core.utils.CommonUtil;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

public class PopClientException extends ClientException {
    private String code;
    private String message;
    private String requestId;
    private Map data;

    public PopClientException() {
        super();
    }

    public PopClientException(final String message) {
        super(message);
    }

    public PopClientException(final Throwable cause) {
        super(cause);
    }

    public PopClientException(final String message, final Throwable cause) {
        super(message, cause);
    }

    public PopClientException(final String message, final Throwable cause, final boolean enableSuppression,
                              final boolean writableStackTrace) {
        super(message, cause, enableSuppression, writableStackTrace);
    }

    public PopClientException(Map map) {
        setData(map);
    }

    public PopClientException(Map map, String message, Throwable cause) {
        super(message, cause);
        setData(map);
    }

    @Override
    public String getMessage() {
        if (!StringUtils.isEmpty(message)) {
            return "\n(Code: " + getErrCode() +
                    "\nMessage: " + getErrMessage() +
                    "\nRequest ID: " + getRequestId() + ")";
        }
        return super.getMessage();
    }

    public String getErrMessage() {
        return message;
    }

    public void setErrMessage(String message) {
        this.message = message;
    }

    public String getErrCode() {
        return code;
    }

    public void setErrCode(String code) {
        this.code = code;
    }

    public String getRequestId() {
        return requestId;
    }

    public void setRequestId(String requestId) {
        this.requestId = requestId;
    }

    public void setData(Map map) {
        this.setErrCode(String.valueOf(map.get("code")));
        this.setErrMessage(String.valueOf(map.get("message")));
        Object obj = map.get("data");
        if (obj == null) {
            return;
        }
        if (obj instanceof Map) {
            data = (Map) obj;
            if (!CommonUtil.isUnset(data.get("RequestId"))) {
                this.setRequestId(data.get("RequestId").toString());
            } else if (!CommonUtil.isUnset(data.get("requestId"))) {
                this.setRequestId(data.get("requestId").toString());
            }
            return;
        }
        Map hashMap = new HashMap();
        Field[] declaredFields = obj.getClass().getDeclaredFields();
        for (Field field : declaredFields) {
            field.setAccessible(true);
            try {
                hashMap.put(field.getName(), field.get(obj));
            } catch (Exception e) {
                continue;
            }
        }
        this.data = hashMap;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy