wangmengmeng
2024-12-24 24432a361d5c6bd6f3d8c008693e9f1155d62517
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package com.dji.sdk.mqtt.services;
 
import com.dji.sdk.cloudapi.control.ControlErrorCodeEnum;
import com.dji.sdk.cloudapi.debug.DebugErrorCodeEnum;
import com.dji.sdk.cloudapi.firmware.FirmwareErrorCodeEnum;
import com.dji.sdk.cloudapi.livestream.LiveErrorCodeEnum;
import com.dji.sdk.cloudapi.log.LogErrorCodeEnum;
import com.dji.sdk.cloudapi.wayline.WaylineErrorCodeEnum;
import com.dji.sdk.common.CommonErrorEnum;
import com.dji.sdk.common.ErrorCodeSourceEnum;
import com.dji.sdk.common.IErrorInfo;
import com.dji.sdk.mqtt.MqttReply;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
 
/**
 * @author sean
 * @version 1.7
 * @date 2023/7/14
 */
public class ServicesErrorCode implements IErrorInfo {
 
    private static final int MOD = 100_000;
 
    private ErrorCodeSourceEnum source;
 
    private IServicesErrorCode errorCode;
 
    private boolean success;
 
    private Integer sourceCode;
 
    @Override
    public String toString() {
        return "{" +
                "errorCode=" + getCode() +
                ", errorMsg=" + getMessage() +
                '}';
    }
 
    @JsonCreator
    public ServicesErrorCode(int code) {
        this.sourceCode = code;
        if (MqttReply.CODE_SUCCESS == code) {
            this.success = true;
            this.errorCode = CommonErrorEnum.SUCCESS;
            return;
        }
        this.source = ErrorCodeSourceEnum.find(code / MOD);
        this.errorCode = LiveErrorCodeEnum.find(code % MOD);
        if (errorCode.getCode() != -1) {
            return;
        }
        this.errorCode = DebugErrorCodeEnum.find(code);
        if (errorCode.getCode() != -1) {
            return;
        }
        this.errorCode = ControlErrorCodeEnum.find(code);
        if (errorCode.getCode() != -1) {
            return;
        }
        this.errorCode = LogErrorCodeEnum.find(code);
        if (errorCode.getCode() != -1) {
            return;
        }
        this.errorCode = FirmwareErrorCodeEnum.find(code);
        if (errorCode.getCode() != -1) {
            return;
        }
        this.errorCode = WaylineErrorCodeEnum.find(code);
        if (errorCode.getCode() != -1) {
            return;
        }
        this.errorCode = CommonErrorEnum.find(code);
    }
 
    @Override
    public String getMessage() {
        return errorCode.getMessage();
    }
 
    @JsonValue
    public Integer getCode() {
        return sourceCode;
    }
 
    public boolean isSuccess() {
        return success;
    }
 
    public ErrorCodeSourceEnum getSource() {
        return source;
    }
}