From 5e978940f99cc7efb572b191618a07573b33e5fa Mon Sep 17 00:00:00 2001 From: Francis Lachapelle Date: Wed, 9 Dec 2015 09:44:33 -0500 Subject: [PATCH] Improve JSON responses from server --- UI/MailerUI/UIxMailEditor.m | 8 ++++++-- UI/PreferencesUI/UIxPreferences.m | 4 ++-- UI/Scheduler/UIxAppointmentActions.m | 16 +++++++++------- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/UI/MailerUI/UIxMailEditor.m b/UI/MailerUI/UIxMailEditor.m index 41e5761b1..ec4260c44 100644 --- a/UI/MailerUI/UIxMailEditor.m +++ b/UI/MailerUI/UIxMailEditor.m @@ -814,6 +814,7 @@ static NSArray *infoKeys = nil; NSMutableArray *errorMsg; NSDictionary *messageSubmissions; SOGoSystemDefaults *dd; + id response; int messages_count, recipients_count; @@ -878,6 +879,8 @@ static NSArray *infoKeys = nil; [errorMsg componentsJoinedByString: @"\n"], @"message", nil]; + response = [self responseWithStatus: 405 + andJSONRepresentation: jsonResponse]; } else { @@ -886,6 +889,8 @@ static NSArray *infoKeys = nil; [co sourceFolder], @"sourceFolder", [NSNumber numberWithInt: [co sourceIMAP4ID]], @"sourceMessageID", nil]; + response = [self responseWithStatus: 200 + andJSONRepresentation: jsonResponse]; recipients_count += [[co allRecipients] count]; messages_count += 1; @@ -898,8 +903,7 @@ static NSArray *infoKeys = nil; } } - return [self responseWithStatus: 200 - andString: [jsonResponse jsonRepresentation]]; + return response; } @end /* UIxMailEditor */ diff --git a/UI/PreferencesUI/UIxPreferences.m b/UI/PreferencesUI/UIxPreferences.m index 2213dd9a6..958634f29 100644 --- a/UI/PreferencesUI/UIxPreferences.m +++ b/UI/PreferencesUI/UIxPreferences.m @@ -2180,12 +2180,12 @@ static NSArray *reminderValues = nil; if (![account updateFilters]) { results = (id ) [self responseWithStatus: 502 - andJSONRepresentation: [NSDictionary dictionaryWithObjectsAndKeys: @"Connection error", @"textStatus", nil]]; + andJSONRepresentation: [NSDictionary dictionaryWithObjectsAndKeys: @"Connection error", @"message", nil]]; } } else results = (id ) [self responseWithStatus: 503 - andJSONRepresentation: [NSDictionary dictionaryWithObjectsAndKeys: @"Service temporarily unavailable", @"textStatus", nil]]; + andJSONRepresentation: [NSDictionary dictionaryWithObjectsAndKeys: @"Service temporarily unavailable", @"message", nil]]; } } diff --git a/UI/Scheduler/UIxAppointmentActions.m b/UI/Scheduler/UIxAppointmentActions.m index 9044c4f01..9d65f5182 100644 --- a/UI/Scheduler/UIxAppointmentActions.m +++ b/UI/Scheduler/UIxAppointmentActions.m @@ -60,7 +60,7 @@ SoSecurityManager *sm; iCalEvent *event; NSCalendarDate *start, *newStart, *end, *newEnd; - NSDictionary *params; + NSDictionary *params, *jsonResponse; NSTimeInterval newDuration; SOGoUserDefaults *ud; NSNumber *daysDelta, *startDelta, *durationDelta; @@ -138,24 +138,26 @@ inContext: context]) ex = [co moveToFolder: targetCalendar]; } - - } if (ex) { - NSDictionary *jsonResponse; jsonResponse = [NSDictionary dictionaryWithObjectsAndKeys: [ex reason], @"message", nil]; response = [self responseWithStatus: 403 - andString: [jsonResponse jsonRepresentation]]; + andJSONRepresentation: jsonResponse]; } else response = [self responseWith204]; } else - response = (WOResponse *) [NSException exceptionWithHTTPStatus: 400 - reason: @"missing 'days', 'start' and/or 'duration' parameters"]; + { + jsonResponse = [NSDictionary dictionaryWithObjectsAndKeys: + @"missing 'days', 'start' and/or 'duration' parameters", @"message", + nil]; + response = [self responseWithStatus: 400 + andJSONRepresentation: jsonResponse]; + } return response; }