mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-06 20:43:44 +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];
|
[[ServiceCom sharedInstance] leaveNetwork:nwid error:&error];
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
// TODO: Display error message
|
NSAlert *alert = [NSAlert alertWithError:error];
|
||||||
|
alert.alertStyle = NSCriticalAlertStyle;
|
||||||
|
[alert addButtonWithTitle:@"Ok"];
|
||||||
|
|
||||||
|
[alert runModal];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -283,7 +286,13 @@
|
||||||
allowDefault:(network.allowDefault && ![Network defaultRouteExists:self.networks])
|
allowDefault:(network.allowDefault && ![Network defaultRouteExists:self.networks])
|
||||||
error:&error];
|
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];
|
error:&error];
|
||||||
|
|
||||||
if(error) {
|
if(error) {
|
||||||
// TODO: display error message
|
NSAlert *alert = [NSAlert alertWithError:error];
|
||||||
|
alert.alertStyle = NSCriticalAlertStyle;
|
||||||
|
[alert addButtonWithTitle:@"Ok"];
|
||||||
|
|
||||||
|
[alert runModal];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -50,7 +50,11 @@
|
||||||
error:&error];
|
error:&error];
|
||||||
|
|
||||||
if (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];
|
[[ServiceCom sharedInstance] leaveNetwork:nwid error:&error];
|
||||||
|
|
||||||
if (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 "ServiceCom.h"
|
||||||
#import "NodeStatus.h"
|
#import "NodeStatus.h"
|
||||||
|
|
||||||
|
@import AppKit;
|
||||||
|
|
||||||
|
|
||||||
NSString * const NetworkUpdateKey = @"com.zerotier.one.network-list";
|
NSString * const NetworkUpdateKey = @"com.zerotier.one.network-list";
|
||||||
NSString * const StatusUpdateKey = @"com.zerotier.one.status";
|
NSString * const StatusUpdateKey = @"com.zerotier.one.status";
|
||||||
|
|
||||||
|
@ -85,9 +88,22 @@ NSString * const StatusUpdateKey = @"com.zerotier.one.status";
|
||||||
} error:&error];
|
} error:&error];
|
||||||
|
|
||||||
if(error) {
|
if(error) {
|
||||||
// TODO: Display error message
|
|
||||||
|
|
||||||
[self stop];
|
[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) {
|
[[ServiceCom sharedInstance] getNodeStatus:^(NodeStatus *status) {
|
||||||
|
@ -101,9 +117,22 @@ NSString * const StatusUpdateKey = @"com.zerotier.one.status";
|
||||||
} error:&error];
|
} error:&error];
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
// TODO: Display error message
|
|
||||||
|
|
||||||
[self stop];
|
[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;
|
NSString *baseURL;
|
||||||
NSURLSession *session;
|
NSURLSession *session;
|
||||||
|
BOOL _isQuitting;
|
||||||
}
|
}
|
||||||
+ (ServiceCom*)sharedInstance;
|
+ (ServiceCom*)sharedInstance;
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#import "AuthtokenCopy.h"
|
#import "AuthtokenCopy.h"
|
||||||
#import "Network.h"
|
#import "Network.h"
|
||||||
#import "NodeStatus.h"
|
#import "NodeStatus.h"
|
||||||
|
@import AppKit;
|
||||||
|
|
||||||
@interface ServiceCom (Private)
|
@interface ServiceCom (Private)
|
||||||
|
|
||||||
|
@ -34,6 +35,7 @@
|
||||||
if(self) {
|
if(self) {
|
||||||
baseURL = @"http://localhost:9993";
|
baseURL = @"http://localhost:9993";
|
||||||
session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration ephemeralSessionConfiguration]];
|
session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration ephemeralSessionConfiguration]];
|
||||||
|
_isQuitting = NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
|
@ -171,24 +173,62 @@
|
||||||
NSURL *url = [NSURL URLWithString:urlString];
|
NSURL *url = [NSURL URLWithString:urlString];
|
||||||
NSURLSessionDataTask *task =
|
NSURLSessionDataTask *task =
|
||||||
[session dataTaskWithURL:url
|
[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) {
|
if (err) {
|
||||||
NSLog(@"Error: %@", error);
|
[[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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*)response;
|
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*)response;
|
||||||
NSInteger status = [httpResponse statusCode];
|
NSInteger status = [httpResponse statusCode];
|
||||||
|
|
||||||
NSError *err;
|
NSError *err2;
|
||||||
|
|
||||||
if (status == 200) {
|
if (status == 200) {
|
||||||
NSArray *json = [NSJSONSerialization JSONObjectWithData:data
|
NSArray *json = [NSJSONSerialization JSONObjectWithData:data
|
||||||
options:0
|
options:0
|
||||||
error:&err];
|
error:&err2];
|
||||||
if (err) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -218,7 +258,25 @@
|
||||||
completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable err) {
|
completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable err) {
|
||||||
|
|
||||||
if(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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -233,6 +291,25 @@
|
||||||
|
|
||||||
if(err2) {
|
if(err2) {
|
||||||
NSLog(@"Error fetching node status: %@", 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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -282,8 +359,27 @@
|
||||||
|
|
||||||
NSURLSessionDataTask *task =
|
NSURLSessionDataTask *task =
|
||||||
[session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable err) {
|
[session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable err) {
|
||||||
if(error) {
|
if(err) {
|
||||||
NSLog(@"Error posting join request: %@", 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;
|
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*)response;
|
||||||
|
@ -320,6 +416,25 @@
|
||||||
[session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable err) {
|
[session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable err) {
|
||||||
if(err) {
|
if(err) {
|
||||||
NSLog(@"Error posting delete request: %@", 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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue