JLChen
2021-11-04 1443556e9ccb1a19ed8e6710c16c8adc4d4f4fb3
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
//
//  Copyright © 2016年 dahua. All rights reserved.
//
 
#import "LCError+LeChange.h"
#import "LCErrorCode.h"
#import "LCProgressHUD.h"
 
@implementation LCError (LeChange)
 
@dynamic errorDescription;
 
- (void)showPlatformTips {
    //【*】鉴权失败不提示
    if ([LCError isAuthenticationFailed:[self.errorCode integerValue]]) {
        return;
    }
    
    NSString *desc = [self.errorInfo objectForKey:@"Desc"];
    if (desc) {
        [LCProgressHUD showMsg:desc];
    }
}
 
- (NSString *)platformTips {
    NSString *desc = [self.errorInfo objectForKey:@"Desc"];
    return desc;
}
 
- (NSString *)errorDescription
{
    NSString *desc;
    switch ([self.errorCode intValue]) {
        //400
        case EC_HTTP_FORMAT:
            return @"mobile_common_network_exception".lc_T;
 
        //404
        case EC_HTTP_NOT_FOUND:
            return @"device_manager_no_network_tip".lc_T;
 
        //500
        case EC_HTTP_INTERNAL_SERVER:
            return @"mobile_common_bec_common_network_unusual".lc_T;
 
        //502
        case EC_HTTP_BAD_GATEWAY:
            return @"mobile_common_bec_common_network_unusual".lc_T;
 
        //503
        case EC_HTTP_SERVICE_UNAVAILABLE:
            return @"mobile_common_bec_common_network_unusual".lc_T;
 
        case -1:
        case -100:
            return @"mobile_common_bec_common_network_unusual".lc_T;
 
        default:
            desc = [self.errorInfo objectForKey:@"Desc"];
    }
 
    return desc.length > 0 ? desc : @"mobile_common_bec_common_unknown".lc_T;
}
 
- (void)showErrorTips:(NSString *)customTips {
    //【*】鉴权失败不提示
    if ([LCError isAuthenticationFailed:[self.errorCode integerValue]]) {
        return;
    }
    
    //SMB 直接使用平台的Desc进行显示
    NSString *desc = [self.errorInfo objectForKey:@"Desc"];
    if (desc && desc.length > 0) {
        [LCProgressHUD showMsg:desc];
        return;
    }
 
    NSString *mTips;
 
    if (customTips.length == 0) {
        //自定义提示为空时,可能显示未知错误
        mTips = [self errorDescription];
    } else {
        //当出现未知错误时,显示自定义错误
        mTips = [[self errorDescription] isEqualToString:@"mobile_common_bec_common_unknown".lc_T] ? customTips : [self errorDescription];
    }
 
    [LCProgressHUD showMsg:mTips];
}
 
- (void)showErrorTips {
    [self showErrorTips:@""];
}
 
- (void)showErrorTipsInView:(UIView *)view
{
    //【*】鉴权失败不提示
    if ([LCError isAuthenticationFailed:[self.errorCode integerValue]]) {
        return;
    }
    
    [LCProgressHUD showMsg:[self errorDescription] inView:view];
}
 
- (NSString *)descriptionByCustom:(NSString *)customTips
{
    NSString *mTips;
 
    if (customTips.length == 0) {
        //自定义提示为空时,可能显示未知错误
        mTips = [self errorDescription];
    } else {
        //当出现未知错误时,显示自定义错误
        mTips = [[self errorDescription] isEqualToString:@"mobile_common_bec_common_unknown".lc_T] ? customTips : [self errorDescription];
    }
 
    return mTips;
}
 
@end