package org.eclipse.paho.mqttv5.common;

import java.util.MissingResourceException;
import java.util.ResourceBundle;
import org.eclipse.paho.mqttv5.common.packet.MqttDisconnect;

/* JADX INFO: loaded from: classes2.dex */
public class MqttException extends Exception {
    public static final short REASON_CODE_CLIENT_EXCEPTION = 0;
    public static final int REASON_CODE_DUPLICATE_PROPERTY = 50005;
    public static final int REASON_CODE_INVALID_IDENTIFIER = 50000;
    public static final int REASON_CODE_INVALID_RETURN_CODE = 50001;
    public static final int REASON_CODE_INVALID_TOPIC_ALAS = 50004;
    public static final int REASON_CODE_MALFORMED_PACKET = 50002;
    public static final int REASON_CODE_UNSUPPORTED_PROTOCOL_VERSION = 50003;
    private static final long serialVersionUID = 1;
    private Throwable cause;
    private int disconnectReasonCode;
    private String disconnectReasonString;
    private int reasonCode;

    public MqttException(int i) {
        this.disconnectReasonCode = 0;
        this.reasonCode = i;
    }

    public MqttException(int i, MqttDisconnect mqttDisconnect) {
        this.disconnectReasonCode = 0;
        this.reasonCode = i;
        if (mqttDisconnect != null) {
            this.disconnectReasonCode = mqttDisconnect.getReturnCode();
            if (mqttDisconnect.getProperties() != null) {
                this.disconnectReasonString = mqttDisconnect.getProperties().getReasonString();
            }
        }
    }

    public MqttException(Throwable th) {
        this.disconnectReasonCode = 0;
        this.reasonCode = 0;
        this.cause = th;
    }

    public MqttException(int i, Throwable th) {
        this.disconnectReasonCode = 0;
        this.reasonCode = i;
        this.cause = th;
    }

    public int getReasonCode() {
        return this.reasonCode;
    }

    @Override // java.lang.Throwable
    public Throwable getCause() {
        return this.cause;
    }

    @Override // java.lang.Throwable
    public String getMessage() {
        String string;
        try {
            string = ResourceBundle.getBundle("org.eclipse.paho.mqttv5.common.nls.messages").getString(Integer.toString(this.reasonCode));
        } catch (MissingResourceException unused) {
            string = "Untranslated MqttException - RC: " + this.reasonCode;
        }
        if (this.disconnectReasonCode != 0) {
            string = String.valueOf(string) + " Disconnect RC: " + this.disconnectReasonCode;
        }
        return this.disconnectReasonString != null ? String.valueOf(string) + " Disconnect Reason: " + this.disconnectReasonString : string;
    }

    @Override // java.lang.Throwable
    public String toString() {
        String str = String.valueOf(getMessage()) + " (" + this.reasonCode + ")";
        return this.cause != null ? String.valueOf(str) + " - " + this.cause.toString() : str;
    }
}
