Fix json error parsing
This commit is contained in:
1 parent
a0d4fdd9ec
commit
faadb6081b
5 files changed
+11
-11
No files matched your search
@@ -86,8 +86,8 @@
|
||||
|
||||
void(^completionBlock)(void) = ^{
|
||||
self.metadata = parseJSONFromFile(path);
|
||||
if (self.metadata[@"NSErrorDescription"]) {
|
||||
[self finishDownloadWithErrorString:self.metadata[@"NSErrorDescription"]];
|
||||
if (self.metadata[@"NSErrorObject"]) {
|
||||
[self finishDownloadWithErrorString:[self.metadata[@"NSErrorObject"] localizedDescription]];
|
||||
return;
|
||||
}
|
||||
if (self.metadata[@"inheritsFrom"]) {
|
||||
@@ -104,8 +104,8 @@
|
||||
if (!version) {
|
||||
// This is likely local version, check if json exists and has inheritsFrom
|
||||
NSMutableDictionary *json = parseJSONFromFile(path);
|
||||
if (json[@"NSErrorDescription"]) {
|
||||
[self finishDownloadWithErrorString:json[@"NSErrorDescription"]];
|
||||
if (json[@"NSErrorObject"]) {
|
||||
[self finishDownloadWithErrorString:[json[@"NSErrorObject"] localizedDescription]];
|
||||
return;
|
||||
} else if (json[@"inheritsFrom"]) {
|
||||
version = (id)[MinecraftResourceUtils findVersion:json[@"inheritsFrom"] inList:remoteVersionList];
|
||||
|
||||
@@ -64,7 +64,7 @@ static PLProfiles* current;
|
||||
self = [super init];
|
||||
self.profilePath = [@(getenv("POJAV_GAME_DIR")) stringByAppendingPathComponent:@"launcher_profiles.json"];
|
||||
self.profileDict = parseJSONFromFile(self.profilePath);
|
||||
if (self.profileDict[@"NSErrorDescription"]) {
|
||||
if (self.profileDict[@"NSErrorObject"]) {
|
||||
self.profileDict = PLProfiles.defaultProfiles;
|
||||
[self save];
|
||||
}
|
||||
|
||||
@@ -20,8 +20,8 @@ static BaseAuthenticator *current = nil;
|
||||
|
||||
+ (id)loadSavedName:(NSString *)name {
|
||||
NSMutableDictionary *authData = parseJSONFromFile([NSString stringWithFormat:@"%s/accounts/%@.json", getenv("POJAV_HOME"), name]);
|
||||
if (authData[@"error"] != nil) {
|
||||
NSError *error = ((NSError *)authData[@"error"]);
|
||||
if (authData[@"NSErrorObject"] != nil) {
|
||||
NSError *error = ((NSError *)authData[@"NSErrorObject"]);
|
||||
if (error.code != NSFileReadNoSuchFileError) {
|
||||
showDialog(localize(@"Error", nil), error.localizedDescription);
|
||||
}
|
||||
|
||||
@@ -27,8 +27,8 @@
|
||||
NSString *controlFilePath = [NSString stringWithFormat:@"%s/controlmap/%@", getenv("POJAV_HOME"), name];
|
||||
|
||||
self.layoutDictionary = parseJSONFromFile(controlFilePath);
|
||||
if (self.layoutDictionary[@"error"] != nil) {
|
||||
showDialog(localize(@"Error", nil), [NSString stringWithFormat:@"Could not open %@: %@", controlFilePath, [self.layoutDictionary[@"error"] localizedDescription]]);
|
||||
if (self.layoutDictionary[@"NSErrorObject"] != nil) {
|
||||
showDialog(localize(@"Error", nil), [NSString stringWithFormat:@"Could not open %@: %@", controlFilePath, [self.layoutDictionary[@"NSErrorObject"] localizedDescription]]);
|
||||
return;
|
||||
}
|
||||
[self loadControlLayout:self.layoutDictionary];
|
||||
|
||||
+2
-2
@@ -68,14 +68,14 @@ NSMutableDictionary* parseJSONFromFile(NSString *path) {
|
||||
NSString *content = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:&error];
|
||||
if (content == nil) {
|
||||
NSLog(@"[ParseJSON] Error: could not read %@: %@", path, error.localizedDescription);
|
||||
return @{@"NSErrorDescription": error.localizedDescription}.mutableCopy;
|
||||
return @{@"NSErrorObject": error}.mutableCopy;
|
||||
}
|
||||
|
||||
NSData* data = [content dataUsingEncoding:NSUTF8StringEncoding];
|
||||
NSMutableDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error];
|
||||
if (error) {
|
||||
NSLog(@"[ParseJSON] Error: could not parse JSON: %@", error.localizedDescription);
|
||||
return [@{@"error": error} mutableCopy];
|
||||
return @{@"NSErrorObject": error}.mutableCopy;
|
||||
}
|
||||
return dict;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user