Skip to content

Commit de36e21

Browse files
committed
refactor: public error utils
1 parent 642c88d commit de36e21

File tree

15 files changed

+192
-180
lines changed

15 files changed

+192
-180
lines changed

AVOS/AVOS.xcodeproj/project.pbxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@
113113
D30B6A9924A09DF2006ABE09 /* LCUser.h in Headers */ = {isa = PBXBuildFile; fileRef = 8C841A9E1A5A7A0000C5C6C4 /* LCUser.h */; settings = {ATTRIBUTES = (Public, ); }; };
114114
D30B6A9A24A09DF2006ABE09 /* LCUser_Internal.h in Headers */ = {isa = PBXBuildFile; fileRef = 8C841AA01A5A7A0000C5C6C4 /* LCUser_Internal.h */; };
115115
D30B6A9B24A09DF2006ABE09 /* LCUser.m in Sources */ = {isa = PBXBuildFile; fileRef = 8C841A9F1A5A7A0000C5C6C4 /* LCUser.m */; };
116-
D30B6A9E24A09E35006ABE09 /* LCErrorUtils.h in Headers */ = {isa = PBXBuildFile; fileRef = 8C841AA21A5A7A0000C5C6C4 /* LCErrorUtils.h */; };
116+
D30B6A9E24A09E35006ABE09 /* LCErrorUtils.h in Headers */ = {isa = PBXBuildFile; fileRef = 8C841AA21A5A7A0000C5C6C4 /* LCErrorUtils.h */; settings = {ATTRIBUTES = (Public, ); }; };
117117
D30B6A9F24A09E35006ABE09 /* LCErrorUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = 8C841AA31A5A7A0000C5C6C4 /* LCErrorUtils.m */; };
118118
D30B6AA024A09E35006ABE09 /* LCHelpers.h in Headers */ = {isa = PBXBuildFile; fileRef = 8C841AA41A5A7A0000C5C6C4 /* LCHelpers.h */; };
119119
D30B6AA124A09E35006ABE09 /* LCLogger.h in Headers */ = {isa = PBXBuildFile; fileRef = 8C841AA61A5A7A0000C5C6C4 /* LCLogger.h */; settings = {ATTRIBUTES = (Public, ); }; };

AVOS/LeanCloudObjc/Foundation.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#import "LCAvailability.h"
1616
#import "LCConstants.h"
1717
#import "LCLogger.h"
18+
#import "LCErrorUtils.h"
1819

1920
// Object
2021
#import "LCObject.h"

AVOS/Sources/Foundation/File/LCFile.m

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ - (void)uploadWithOption:(LCFileUploadOption)uploadOption
630630
dispatch_async(dispatch_get_main_queue(), ^{
631631
completionHandler(false, ({
632632
NSString *reason = @"File is in uploading, Can't do repeated upload operation.";
633-
LCErrorInternal(reason);
633+
LCErrorInternalServer(reason);
634634
}));
635635
});
636636

@@ -749,7 +749,7 @@ - (void)uploadWithOption:(LCFileUploadOption)uploadOption
749749

750750
completionHandler(false, ({
751751
NSString *reason = @"No data or URL to Upload.";
752-
LCErrorInternal(reason);
752+
LCErrorInternalServer(reason);
753753
}));
754754
});
755755
}
@@ -879,7 +879,7 @@ - (void)uploadRemoteURLWithCompletionHandler:(void (^)(BOOL succeeded, NSError *
879879

880880
completionHandler(false, ({
881881
NSString *reason = @"response invalid.";
882-
LCErrorInternal(reason);
882+
LCErrorInternalServer(reason);
883883
}));
884884

885885
return;
@@ -909,7 +909,7 @@ - (void)getFileTokensWithParameters:(NSDictionary *)parameters
909909
if (![NSDictionary _lc_isTypeOf:dic]) {
910910
callback(nil, ({
911911
NSString *reason = @"fileTokens response invalid.";
912-
LCErrorInternal(reason);
912+
LCErrorInternalServer(reason);
913913
}));
914914
return;
915915
}
@@ -955,7 +955,7 @@ - (void)downloadWithOption:(LCFileDownloadOption)downloadOption
955955
dispatch_async(dispatch_get_main_queue(), ^{
956956
completionHandler(nil, ({
957957
NSString *reason = @"File is in downloading, Can't do repeated download operation.";
958-
LCErrorInternal(reason);
958+
LCErrorInternalServer(reason);
959959
}));
960960
});
961961

@@ -969,7 +969,7 @@ - (void)downloadWithOption:(LCFileDownloadOption)downloadOption
969969
dispatch_async(dispatch_get_main_queue(), ^{
970970
completionHandler(nil, ({
971971
NSString *reason = @"url is invalid.";
972-
LCErrorInternal(reason);
972+
LCErrorInternalServer(reason);
973973
}));
974974
});
975975

@@ -1134,7 +1134,7 @@ - (NSString *)persistentCachePathThrowError:(NSError * __autoreleasing *)error
11341134
if (error) {
11351135
*error = ({
11361136
NSString *reason = @"objectId invalid.";
1137-
LCErrorInternal(reason);
1137+
LCErrorInternalServer(reason);
11381138
});
11391139
}
11401140
return nil;
@@ -1178,7 +1178,7 @@ - (void)deleteWithCompletionHandler:(void (^)(BOOL, NSError * _Nullable))complet
11781178

11791179
NSError *aError = ({
11801180
NSString *reason = @"`objectId` is invalid.";
1181-
LCErrorInternal(reason);
1181+
LCErrorInternalServer(reason);
11821182
});
11831183

11841184
completionHandler(false, aError);
@@ -1256,7 +1256,7 @@ + (void)getFileWithObjectId:(NSString *)objectId
12561256

12571257
NSError *aError = ({
12581258
NSString *reason = @"`objectId` is invalid.";
1259-
LCErrorInternal(reason);
1259+
LCErrorInternalServer(reason);
12601260
});
12611261

12621262
completionHandler(nil, aError);
@@ -1283,7 +1283,7 @@ + (void)getFileWithObjectId:(NSString *)objectId
12831283

12841284
NSError *aError = ({
12851285
NSString *reason = @"Get an invalid Object.";
1286-
LCErrorInternal(reason);
1286+
LCErrorInternalServer(reason);
12871287
});
12881288

12891289
completionHandler(nil, aError);

AVOS/Sources/Foundation/File/LCFileTaskManager.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ - (NSURLSessionUploadTask *)uploadTaskWithData:(NSData *)data
161161

162162
NSError *aError = ({
163163
NSString *reason = [NSString stringWithFormat:@"Provider: (%@) can't be matched.", fileTokens.provider];
164-
LCErrorInternal(reason);
164+
LCErrorInternalServer(reason);
165165
});
166166

167167
uploadCompletionHandler(false, aError);
@@ -260,7 +260,7 @@ - (NSURLSessionUploadTask *)uploadTaskWithLocalPath:(NSString *)localPath
260260

261261
NSError *aError = ({
262262
NSString *reason = [NSString stringWithFormat:@"Provider: (%@) can't be matched.", fileTokens.provider];
263-
LCErrorInternal(reason);
263+
LCErrorInternalServer(reason);
264264
});
265265

266266
uploadCompletionHandler(false, aError);
@@ -382,7 +382,7 @@ - (NSURLSessionUploadTask *)uploadToQCloudWithRequest:(NSURLRequest *)request
382382

383383
NSError *aError = ({
384384
NSString *reason = [NSString stringWithFormat:@"%@", dic];
385-
LCErrorInternal(reason);
385+
LCErrorInternalServer(reason);
386386
});
387387

388388
uploadCompletionHandler(false, aError);

AVOS/Sources/Foundation/LCConstants.h

Lines changed: 0 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -38,124 +38,6 @@ typedef NS_ENUM(int, LCCachePolicy) {
3838
kLCCachePolicyCacheThenNetwork,
3939
} ;
4040

41-
// Errors
42-
43-
FOUNDATION_EXPORT NSString * _Nonnull const kLeanCloudErrorDomain;
44-
FOUNDATION_EXPORT NSString * _Nonnull const kLeanCloudRESTAPIResponseError;
45-
46-
/*! @abstract 1: Internal server error. No information available. */
47-
extern NSInteger const kLCErrorInternalServer;
48-
/*! @abstract 100: The connection to the LeanCloud servers failed. */
49-
extern NSInteger const kLCErrorConnectionFailed;
50-
/*! @abstract 101: Object doesn't exist, or has an incorrect password. */
51-
extern NSInteger const kLCErrorObjectNotFound;
52-
/*! @abstract 102: You tried to find values matching a datatype that doesn't support exact database matching, like an array or a dictionary. */
53-
extern NSInteger const kLCErrorInvalidQuery;
54-
/*! @abstract 103: Missing or invalid classname. Classnames are case-sensitive. They must start with a letter, and a-zA-Z0-9_ are the only valid characters. */
55-
extern NSInteger const kLCErrorInvalidClassName;
56-
/*! @abstract 104: Missing object id. */
57-
extern NSInteger const kLCErrorMissingObjectId;
58-
/*! @abstract 105: Invalid key name. Keys are case-sensitive. They must start with a letter, and a-zA-Z0-9_ are the only valid characters. */
59-
extern NSInteger const kLCErrorInvalidKeyName;
60-
/*! @abstract 106: Malformed pointer. Pointers must be arrays of a classname and an object id. */
61-
extern NSInteger const kLCErrorInvalidPointer;
62-
/*! @abstract 107: Malformed json object. A json dictionary is expected. */
63-
extern NSInteger const kLCErrorInvalidJSON;
64-
/*! @abstract 108: Tried to access a feature only available internally. */
65-
extern NSInteger const kLCErrorCommandUnavailable;
66-
/*! @abstract 111: Field set to incorrect type. */
67-
extern NSInteger const kLCErrorIncorrectType;
68-
/*! @abstract 112: Invalid channel name. A channel name is either an empty string (the broadcast channel) or contains only a-zA-Z0-9_ characters and starts with a letter. */
69-
extern NSInteger const kLCErrorInvalidChannelName;
70-
/*! @abstract 114: Invalid device token. */
71-
extern NSInteger const kLCErrorInvalidDeviceToken;
72-
/*! @abstract 115: Push is misconfigured. See details to find out how. */
73-
extern NSInteger const kLCErrorPushMisconfigured;
74-
/*! @abstract 116: The object is too large. */
75-
extern NSInteger const kLCErrorObjectTooLarge;
76-
/*! @abstract 119: That operation isn't allowed for clients. */
77-
extern NSInteger const kLCErrorOperationForbidden;
78-
/*! @abstract 120: The results were not found in the cache. */
79-
extern NSInteger const kLCErrorCacheMiss;
80-
/*! @abstract 121: Keys in NSDictionary values may not include '$' or '.'. */
81-
extern NSInteger const kLCErrorInvalidNestedKey;
82-
/*! @abstract 122: Invalid file name. A file name contains only a-zA-Z0-9_. characters and is between 1 and 36 characters. */
83-
extern NSInteger const kLCErrorInvalidFileName;
84-
/*! @abstract 123: Invalid ACL. An ACL with an invalid format was saved. This should not happen if you use LCACL. */
85-
extern NSInteger const kLCErrorInvalidACL;
86-
/*! @abstract 124: The request timed out on the server. Typically this indicates the request is too expensive. */
87-
extern NSInteger const kLCErrorTimeout;
88-
/*! @abstract 125: The email address was invalid. */
89-
extern NSInteger const kLCErrorInvalidEmailAddress;
90-
/*! @abstract 137: A unique field was given a value that is already taken. */
91-
extern NSInteger const kLCErrorDuplicateValue;
92-
/*! @abstract 139: Role's name is invalid. */
93-
extern NSInteger const kLCErrorInvalidRoleName;
94-
/*! @abstract 140: Exceeded an application quota. Upgrade to resolve. */
95-
extern NSInteger const kLCErrorExceededQuota;
96-
/*! @abstract 141: Cloud Code script had an error. */
97-
extern NSInteger const kLCScriptError;
98-
/*! @abstract 142: Cloud Code validation failed. */
99-
extern NSInteger const kLCValidationError;
100-
/*! @abstract 143: Product purchase receipt is missing */
101-
extern NSInteger const kLCErrorReceiptMissing;
102-
/*! @abstract 144: Product purchase receipt is invalid */
103-
extern NSInteger const kLCErrorInvalidPurchaseReceipt;
104-
/*! @abstract 145: Payment is disabled on this device */
105-
extern NSInteger const kLCErrorPaymentDisabled;
106-
/*! @abstract 146: The product identifier is invalid */
107-
extern NSInteger const kLCErrorInvalidProductIdentifier;
108-
/*! @abstract 147: The product is not found in the App Store */
109-
extern NSInteger const kLCErrorProductNotFoundInAppStore;
110-
/*! @abstract 148: The Apple server response is not valid */
111-
extern NSInteger const kLCErrorInvalidServerResponse;
112-
/*! @abstract 149: Product fails to download due to file system error */
113-
extern NSInteger const kLCErrorProductDownloadFileSystemFailure;
114-
/*! @abstract 150: Fail to convert data to image. */
115-
extern NSInteger const kLCErrorInvalidImageData;
116-
/*! @abstract 151: Unsaved file. */
117-
extern NSInteger const kLCErrorUnsavedFile;
118-
/*! @abstract 153: Fail to delete file. */
119-
extern NSInteger const kLCErrorFileDeleteFailure;
120-
/*! @abstract 200: Username is missing or empty */
121-
extern NSInteger const kLCErrorUsernameMissing;
122-
/*! @abstract 201: Password is missing or empty */
123-
extern NSInteger const kLCErrorUserPasswordMissing;
124-
/*! @abstract 202: Username has already been taken */
125-
extern NSInteger const kLCErrorUsernameTaken;
126-
/*! @abstract 203: Email has already been taken */
127-
extern NSInteger const kLCErrorUserEmailTaken;
128-
/*! @abstract 204: The email is missing, and must be specified */
129-
extern NSInteger const kLCErrorUserEmailMissing;
130-
/*! @abstract 205: A user with the specified email was not found */
131-
extern NSInteger const kLCErrorUserWithEmailNotFound;
132-
/*! @abstract 206: The user cannot be altered by a client without the session. */
133-
extern NSInteger const kLCErrorUserCannotBeAlteredWithoutSession;
134-
/*! @abstract 207: Users can only be created through sign up */
135-
extern NSInteger const kLCErrorUserCanOnlyBeCreatedThroughSignUp;
136-
/*! @abstract 208: An existing account already linked to another user. */
137-
extern NSInteger const kLCErrorAccountAlreadyLinked;
138-
/*! @abstract 209: User ID mismatch */
139-
extern NSInteger const kLCErrorUserIdMismatch;
140-
/*! @abstract 210: The username and password mismatch. */
141-
extern NSInteger const kLCErrorUsernamePasswordMismatch;
142-
/*! @abstract 211: Could not find user. */
143-
extern NSInteger const kLCErrorUserNotFound;
144-
/*! @abstract 212: The mobile phone number is missing, and must be specified. */
145-
extern NSInteger const kLCErrorUserMobilePhoneMissing;
146-
/*! @abstract 213: An user with the specified mobile phone number was not found. */
147-
extern NSInteger const kLCErrorUserWithMobilePhoneNotFound;
148-
/*! @abstract 214: Mobile phone number has already been taken. */
149-
extern NSInteger const kLCErrorUserMobilePhoneNumberTaken;
150-
/*! @abstract 215: Mobile phone number isn't verified. */
151-
extern NSInteger const kLCErrorUserMobilePhoneNotVerified;
152-
/*! @abstract 216: SNS Auth Data's format is invalid. */
153-
extern NSInteger const kLCErrorUserSNSAuthDataInvalid;
154-
/*! @abstract 250: Linked id missing from request */
155-
extern NSInteger const kLCErrorLinkedIdMissing;
156-
/*! @abstract 251: Invalid linked session */
157-
extern NSInteger const kLCErrorInvalidLinkedSession;
158-
15941
typedef void (^LCBooleanResultBlock)(BOOL succeeded, NSError * _Nullable error);
16042
typedef void (^LCIntegerResultBlock)(NSInteger number, NSError * _Nullable error);
16143
typedef void (^LCArrayResultBlock)(NSArray * _Nullable objects, NSError * _Nullable error);

AVOS/Sources/Foundation/Request/LCPaasClient.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ -(void)postBatchObject:(NSArray *)requests headerMap:(NSDictionary *)headerMap e
391391
if (error) {
392392
block(nil, error);
393393
} else {
394-
block(nil, LCErrorInternal(@"The batch count of server response is not equal to request count"));
394+
block(nil, LCErrorInternalServer(@"The batch count of server response is not equal to request count"));
395395
}
396396
} else {
397397
// 网络请求成功

AVOS/Sources/Foundation/Router/LCRouter.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ - (instancetype)init
5757
NSError *error = nil;
5858
NSMutableDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error];
5959
if (error || ![NSMutableDictionary _lc_isTypeOf:dictionary]) {
60-
if (!error) { error = LCErrorInternal([NSString stringWithFormat:@"file: %@ is invalid.", filePath]); }
60+
if (!error) { error = LCErrorInternalServer([NSString stringWithFormat:@"file: %@ is invalid.", filePath]); }
6161
LCLoggerError(LCLoggerDomainDefault, @"%@", error);
6262
} else {
6363
return dictionary;
@@ -126,7 +126,7 @@ static void cachingRouterData(NSDictionary *routerDataMap, RouterCacheKey key)
126126
NSError *error = nil;
127127
NSData *data = [NSJSONSerialization dataWithJSONObject:routerDataMap options:0 error:&error];
128128
if (error || ![data length]) {
129-
if (!error) { error = LCErrorInternal(@"data invalid."); }
129+
if (!error) { error = LCErrorInternalServer(@"data invalid."); }
130130
LCLoggerError(LCLoggerDomainDefault, @"%@", error);
131131
return;
132132
}
@@ -144,7 +144,7 @@ static void cachingRouterData(NSDictionary *routerDataMap, RouterCacheKey key)
144144
return;
145145
}
146146
} else if (isExists && !isDirectory) {
147-
LCLoggerError(LCLoggerDomainDefault, @"%@", LCErrorInternal(@"can't create directory for router."));
147+
LCLoggerError(LCLoggerDomainDefault, @"%@", LCErrorInternalServer(@"can't create directory for router."));
148148
return;
149149
}
150150
[routerCacheDirectoryPath stringByAppendingPathComponent:key];
@@ -194,7 +194,7 @@ - (void)getAppRouterDataWithAppID:(NSString *)appID callback:(void (^)(NSDiction
194194
if ([NSDictionary _lc_isTypeOf:dictionary]) {
195195
callback(dictionary, nil);
196196
} else {
197-
callback(nil, LCErrorInternal(@"response data invalid."));
197+
callback(nil, LCErrorInternalServer(@"response data invalid."));
198198
}
199199
}
200200
}];

AVOS/Sources/Foundation/Status/LCStatus.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,12 +234,12 @@ +(void)deleteStatusWithID:(NSString *)objectId andCallback:(LCBooleanResultBlock
234234

235235
+ (BOOL)deleteInboxStatusForMessageId:(NSUInteger)messageId inboxType:(NSString *)inboxType receiver:(NSString *)receiver error:(NSError *__autoreleasing *)error {
236236
if (!receiver) {
237-
if (error) *error = LCErrorInternal(@"Receiver of status can not be nil.");
237+
if (error) *error = LCErrorInternalServer(@"Receiver of status can not be nil.");
238238
return NO;
239239
}
240240

241241
if (!inboxType) {
242-
if (error) *error = LCErrorInternal(@"Inbox type of status can not be nil.");
242+
if (error) *error = LCErrorInternalServer(@"Inbox type of status can not be nil.");
243243
return NO;
244244
}
245245

AVOS/Sources/Foundation/User/LCUser.m

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ + (instancetype)currentUser
9292

9393
- (void)isAuthenticatedWithSessionToken:(NSString *)sessionToken callback:(LCBooleanResultBlock)callback {
9494
if (sessionToken == nil) {
95-
[LCUtils callBooleanResultBlock:callback error:LCErrorInternal(@"sessionToken is nil")];
95+
[LCUtils callBooleanResultBlock:callback error:LCErrorInternalServer(@"sessionToken is nil")];
9696
return;
9797
}
9898

@@ -450,7 +450,7 @@ + (void)becomeWithSessionTokenInBackground:(NSString *)sessionToken block:(LCUse
450450
+ (void)internalBecomeWithSessionTokenInBackground:(NSString *)sessionToken block:(LCUserResultBlock)block {
451451
if (sessionToken == nil) {
452452
if (block) {
453-
block(nil, LCErrorInternal(@"sessionToken is nil"));
453+
block(nil, LCErrorInternalServer(@"sessionToken is nil"));
454454
}
455455
return;
456456
}
@@ -955,7 +955,7 @@ - (void)loginWithAuthData:(NSDictionary *)authData
955955

956956
callback(false, ({
957957
NSString *reason = @"response invalid.";
958-
LCErrorInternal(reason);
958+
LCErrorInternalServer(reason);
959959
}));
960960
});
961961

@@ -987,7 +987,7 @@ - (void)associateWithAuthData:(NSDictionary *)authData
987987

988988
NSError *aError = ({
989989
NSString *reason = @"objectId invalid.";
990-
LCErrorInternal(reason);
990+
LCErrorInternalServer(reason);
991991
});
992992

993993
callback(false, aError);
@@ -1046,7 +1046,7 @@ - (void)associateWithAuthData:(NSDictionary *)authData
10461046

10471047
callback(false, ({
10481048
NSString *reason = @"response invalid.";
1049-
LCErrorInternal(reason);
1049+
LCErrorInternalServer(reason);
10501050
}));
10511051
});
10521052

@@ -1089,7 +1089,7 @@ - (void)disassociateWithPlatformId:(NSString *)platformId
10891089

10901090
NSError *aError = ({
10911091
NSString *reason = @"objectId invalid.";
1092-
LCErrorInternal(reason);
1092+
LCErrorInternalServer(reason);
10931093
});
10941094

10951095
callback(false, aError);
@@ -1124,7 +1124,7 @@ - (void)disassociateWithPlatformId:(NSString *)platformId
11241124

11251125
callback(false, ({
11261126
NSString *reason = @"response invalid.";
1127-
LCErrorInternal(reason);
1127+
LCErrorInternalServer(reason);
11281128
}));
11291129
});
11301130

@@ -1379,7 +1379,7 @@ - (void)getFollowersAndFollowees:(LCDictionaryResultBlock)callback {
13791379
[dict setObject:result forKey:@"followers"];
13801380
}
13811381
@catch (NSException *exception) {
1382-
error = LCErrorInternal(@"wrong format return");
1382+
error = LCErrorInternalServer(@"wrong format return");
13831383
}
13841384
@finally {
13851385
[LCUtils callIdResultBlock:callback object:dict error:error];

0 commit comments

Comments
 (0)