mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-04-16 12:06:55 +02:00
Added error handling messages
This commit is contained in:
parent
c2a01f6db4
commit
94263ffcc1
6 changed files with 183 additions and 17 deletions
|
@ -271,8 +271,11 @@
|
|||
[[ServiceCom sharedInstance] leaveNetwork:nwid error:&error];
|
||||
|
||||
if (error) {
|
||||
// TODO: Display error message
|
||||
NSAlert *alert = [NSAlert alertWithError:error];
|
||||
alert.alertStyle = NSCriticalAlertStyle;
|
||||
[alert addButtonWithTitle:@"Ok"];
|
||||
|
||||
[alert runModal];
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
@ -283,7 +286,13 @@
|
|||
allowDefault:(network.allowDefault && ![Network defaultRouteExists:self.networks])
|
||||
error:&error];
|
||||
|
||||
// TODO: Display error message
|
||||
if (error) {
|
||||
NSAlert *alert = [NSAlert alertWithError:error];
|
||||
alert.alertStyle = NSCriticalAlertStyle;
|
||||
[alert addButtonWithTitle:@"Ok"];
|
||||
|
||||
[alert runModal];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -80,7 +80,11 @@ NSString * const JoinedNetworksKey = @"com.zerotier.one.joined-networks";
|
|||
error:&error];
|
||||
|
||||
if(error) {
|
||||
// TODO: display error message
|
||||
NSAlert *alert = [NSAlert alertWithError:error];
|
||||
alert.alertStyle = NSCriticalAlertStyle;
|
||||
[alert addButtonWithTitle:@"Ok"];
|
||||
|
||||
[alert runModal];
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -50,7 +50,11 @@
|
|||
error:&error];
|
||||
|
||||
if (error) {
|
||||
// TODO: Display error message
|
||||
NSAlert *alert = [NSAlert alertWithError:error];
|
||||
alert.alertStyle = NSCriticalAlertStyle;
|
||||
[alert addButtonWithTitle:@"Ok"];
|
||||
|
||||
[alert runModal];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -60,7 +64,11 @@
|
|||
[[ServiceCom sharedInstance] leaveNetwork:nwid error:&error];
|
||||
|
||||
if (error) {
|
||||
// TODO: Display error message
|
||||
NSAlert *alert = [NSAlert alertWithError:error];
|
||||
alert.alertStyle = NSCriticalAlertStyle;
|
||||
[alert addButtonWithTitle:@"Ok"];
|
||||
|
||||
[alert runModal];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,9 @@
|
|||
#import "ServiceCom.h"
|
||||
#import "NodeStatus.h"
|
||||
|
||||
@import AppKit;
|
||||
|
||||
|
||||
NSString * const NetworkUpdateKey = @"com.zerotier.one.network-list";
|
||||
NSString * const StatusUpdateKey = @"com.zerotier.one.status";
|
||||
|
||||
|
@ -85,9 +88,22 @@ NSString * const StatusUpdateKey = @"com.zerotier.one.status";
|
|||
} error:&error];
|
||||
|
||||
if(error) {
|
||||
// TODO: Display error message
|
||||
|
||||
[self stop];
|
||||
|
||||
NSAlert *alert = [NSAlert alertWithError:error];
|
||||
alert.alertStyle = NSCriticalAlertStyle;
|
||||
[alert addButtonWithTitle:@"Quit"];
|
||||
[alert addButtonWithTitle:@"Retry"];
|
||||
|
||||
NSModalResponse res = [alert runModal];
|
||||
|
||||
if(res == NSAlertFirstButtonReturn) {
|
||||
[NSApp performSelector:@selector(terminate:) withObject:nil afterDelay:0.0];
|
||||
}
|
||||
else if(res == NSAlertSecondButtonReturn) {
|
||||
[self start];
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
[[ServiceCom sharedInstance] getNodeStatus:^(NodeStatus *status) {
|
||||
|
@ -101,9 +117,22 @@ NSString * const StatusUpdateKey = @"com.zerotier.one.status";
|
|||
} error:&error];
|
||||
|
||||
if (error) {
|
||||
// TODO: Display error message
|
||||
|
||||
[self stop];
|
||||
|
||||
NSAlert *alert = [NSAlert alertWithError:error];
|
||||
alert.alertStyle = NSCriticalAlertStyle;
|
||||
[alert addButtonWithTitle:@"Quit"];
|
||||
[alert addButtonWithTitle:@"Retry"];
|
||||
|
||||
NSModalResponse res = [alert runModal];
|
||||
|
||||
if(res == NSAlertFirstButtonReturn) {
|
||||
[NSApp performSelector:@selector(terminate:) withObject:nil afterDelay:0.0];
|
||||
}
|
||||
else if(res == NSAlertSecondButtonReturn) {
|
||||
[self start];
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
{
|
||||
NSString *baseURL;
|
||||
NSURLSession *session;
|
||||
BOOL _isQuitting;
|
||||
}
|
||||
+ (ServiceCom*)sharedInstance;
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#import "AuthtokenCopy.h"
|
||||
#import "Network.h"
|
||||
#import "NodeStatus.h"
|
||||
@import AppKit;
|
||||
|
||||
@interface ServiceCom (Private)
|
||||
|
||||
|
@ -34,6 +35,7 @@
|
|||
if(self) {
|
||||
baseURL = @"http://localhost:9993";
|
||||
session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration ephemeralSessionConfiguration]];
|
||||
_isQuitting = NO;
|
||||
}
|
||||
|
||||
return self;
|
||||
|
@ -171,24 +173,62 @@
|
|||
NSURL *url = [NSURL URLWithString:urlString];
|
||||
NSURLSessionDataTask *task =
|
||||
[session dataTaskWithURL:url
|
||||
completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
|
||||
completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable err) {
|
||||
|
||||
if (error) {
|
||||
NSLog(@"Error: %@", error);
|
||||
if (err) {
|
||||
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
|
||||
NSAlert *alert = [NSAlert alertWithError:err];
|
||||
alert.alertStyle = NSCriticalAlertStyle;
|
||||
[alert addButtonWithTitle:@"Quit"];
|
||||
[alert addButtonWithTitle:@"Retry"];
|
||||
|
||||
NSModalResponse res;
|
||||
if (!_isQuitting) {
|
||||
res = [alert runModal];
|
||||
}
|
||||
else {
|
||||
return;
|
||||
}
|
||||
|
||||
if(res == NSAlertFirstButtonReturn) {
|
||||
[NSApp performSelector:@selector(terminate:) withObject:nil afterDelay:0.0];
|
||||
_isQuitting = YES;
|
||||
}
|
||||
}];
|
||||
return;
|
||||
}
|
||||
|
||||
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*)response;
|
||||
NSInteger status = [httpResponse statusCode];
|
||||
|
||||
NSError *err;
|
||||
NSError *err2;
|
||||
|
||||
if (status == 200) {
|
||||
NSArray *json = [NSJSONSerialization JSONObjectWithData:data
|
||||
options:0
|
||||
error:&err];
|
||||
error:&err2];
|
||||
if (err) {
|
||||
NSLog(@"Error fetching network list: %@", err);
|
||||
NSLog(@"Error fetching network list: %@", err2);
|
||||
|
||||
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
|
||||
NSAlert *alert = [NSAlert alertWithError:err2];
|
||||
alert.alertStyle = NSCriticalAlertStyle;
|
||||
[alert addButtonWithTitle:@"Quit"];
|
||||
[alert addButtonWithTitle:@"Retry"];
|
||||
|
||||
NSModalResponse res;
|
||||
if (!_isQuitting) {
|
||||
res = [alert runModal];
|
||||
}
|
||||
else {
|
||||
return;
|
||||
}
|
||||
|
||||
if(res == NSAlertFirstButtonReturn) {
|
||||
_isQuitting = YES;
|
||||
[NSApp performSelector:@selector(terminate:) withObject:nil afterDelay:0.0];
|
||||
}
|
||||
}];
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -218,7 +258,25 @@
|
|||
completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable err) {
|
||||
|
||||
if(err) {
|
||||
NSLog(@"Error: %@", err);
|
||||
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
|
||||
NSAlert *alert = [NSAlert alertWithError:err];
|
||||
alert.alertStyle = NSCriticalAlertStyle;
|
||||
[alert addButtonWithTitle:@"Quit"];
|
||||
[alert addButtonWithTitle:@"Retry"];
|
||||
|
||||
NSModalResponse res;
|
||||
if (!_isQuitting) {
|
||||
res = [alert runModal];
|
||||
}
|
||||
else {
|
||||
return;
|
||||
}
|
||||
|
||||
if(res == NSAlertFirstButtonReturn) {
|
||||
[NSApp performSelector:@selector(terminate:) withObject:nil afterDelay:0.0];
|
||||
_isQuitting = YES;
|
||||
}
|
||||
}];
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -233,6 +291,25 @@
|
|||
|
||||
if(err2) {
|
||||
NSLog(@"Error fetching node status: %@", err2);
|
||||
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
|
||||
NSAlert *alert = [NSAlert alertWithError:err2];
|
||||
alert.alertStyle = NSCriticalAlertStyle;
|
||||
[alert addButtonWithTitle:@"Quit"];
|
||||
[alert addButtonWithTitle:@"Retry"];
|
||||
|
||||
NSModalResponse res;
|
||||
if (!_isQuitting) {
|
||||
res = [alert runModal];
|
||||
}
|
||||
else {
|
||||
return;
|
||||
}
|
||||
|
||||
if(res == NSAlertFirstButtonReturn) {
|
||||
[NSApp performSelector:@selector(terminate:) withObject:nil afterDelay:0.0];
|
||||
_isQuitting = YES;
|
||||
}
|
||||
}];
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -282,8 +359,27 @@
|
|||
|
||||
NSURLSessionDataTask *task =
|
||||
[session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable err) {
|
||||
if(error) {
|
||||
if(err) {
|
||||
NSLog(@"Error posting join request: %@", err);
|
||||
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
|
||||
NSAlert *alert = [NSAlert alertWithError:err];
|
||||
alert.alertStyle = NSCriticalAlertStyle;
|
||||
[alert addButtonWithTitle:@"Quit"];
|
||||
[alert addButtonWithTitle:@"Retry"];
|
||||
|
||||
NSModalResponse res;
|
||||
if (!_isQuitting) {
|
||||
res = [alert runModal];
|
||||
}
|
||||
else {
|
||||
return;
|
||||
}
|
||||
|
||||
if(res == NSAlertFirstButtonReturn) {
|
||||
[NSApp performSelector:@selector(terminate:) withObject:nil afterDelay:0.0];
|
||||
_isQuitting = YES;
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*)response;
|
||||
|
@ -320,6 +416,25 @@
|
|||
[session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable err) {
|
||||
if(err) {
|
||||
NSLog(@"Error posting delete request: %@", err);
|
||||
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
|
||||
NSAlert *alert = [NSAlert alertWithError:err];
|
||||
alert.alertStyle = NSCriticalAlertStyle;
|
||||
[alert addButtonWithTitle:@"Quit"];
|
||||
[alert addButtonWithTitle:@"Retry"];
|
||||
|
||||
NSModalResponse res;
|
||||
if (!_isQuitting) {
|
||||
res = [alert runModal];
|
||||
}
|
||||
else {
|
||||
return;
|
||||
}
|
||||
|
||||
if(res == NSAlertFirstButtonReturn) {
|
||||
[NSApp performSelector:@selector(terminate:) withObject:nil afterDelay:0.0];
|
||||
_isQuitting = YES;
|
||||
}
|
||||
}];
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue