Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error handling for code generation and update client #179

Merged
merged 2 commits into from
Sep 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dart_wormhole_william
1 change: 0 additions & 1 deletion lib/views/shared/receive.dart
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ class ReceiveSharedState extends ChangeNotifier {
this.error = '';
this.errorMessage = error.toString();
this.errorTitle = SOMETHING_WENT_WRONG;
print("$ERROR_RECEIVING_FILE\n$error");

if (error is ClientError) {
switch (error.errorCode) {
Expand Down
105 changes: 52 additions & 53 deletions lib/views/shared/send.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,62 @@ class SendSharedState extends ChangeNotifier {
});
}

void defaultErrorHandler(Object error) {
this.setState(() {
currentState = SendScreenStates.SendError;
this.errorMessage = "$ERROR_SENDING_FILE: $error";
this.error = '';
this.errorTitle = ERROR_SENDING_FILE;

if (error is ClientError) {
switch (error.errorCode) {
case ErrCodeTransferRejected:
this.errorTitle = TRANSFER_CANCELLED;
this.error = THE_RECEIVER_REJECTED_THIS_TRANSFER;
break;
case ErrCodeTransferCancelled:
this.errorTitle = TRANSFER_CANCELLED;
this.error = YOU_HAVE_CANCELLED_THE_TRANSFER;
break;
case ErrCodeTransferCancelledByReceiver:
this.errorTitle = TRANSFER_CANCELLED_INTERRUPTED;
this.error = EITHER_THE_TRANSFER_WAS_CANCELLED_BY;
break;
case ErrCodeWrongCode:
this.errorTitle = OOPS;
this.error = THE_RECEIVER_HAS_ENTERED_THE_WRONG_CODE;
break;
case ErrCodeSendTextError:
this.errorTitle = SOMETHING_WENT_WRONG;
// TODO: map error to user friendly name (case invalid nameplate)
break;
case ErrCodeSendFileError:
this.errorTitle = SOMETHING_WENT_WRONG;
// TODO: map error to user friendly name (case invalid nameplate)
break;
case ErrCodeConnectionRefused:
this.errorTitle = OOPS;
this.error = ERR_CONNECTION_REFUSED;
break;
default:
this.errorTitle = SOMETHING_WENT_WRONG;
// TODO: map error to user friendly name (case invalid nameplate)
break;
}
}
});

throw error;
}

Future<void> send(f.File file) async {
setState(() {
sendingFile = file;
currentState = SendScreenStates.CodeGenerating;
});

return await client
.sendFile(file, progress.progressHandler)
.then((result) async {
return await client.sendFile(file, progress.progressHandler).then(
(result) async {
setState(() {
code = result.code;
currentState = SendScreenStates.CodeGenerated;
Expand All @@ -116,55 +163,8 @@ class SendSharedState extends ChangeNotifier {
setState(() {
currentState = SendScreenStates.FileSent;
});
}, onError: (error, stacktrace) {
this.setState(() {
currentState = SendScreenStates.SendError;
this.errorMessage = "$ERROR_SENDING_FILE: $error";
this.errorTitle = ERROR_SENDING_FILE;

print("$ERROR_SENDING_FILE\n$error\n$stacktrace");

if (error is ClientError) {
switch (error.errorCode) {
case ErrCodeTransferRejected:
this.errorTitle = TRANSFER_CANCELLED;
this.error = THE_RECEIVER_REJECTED_THIS_TRANSFER;
break;
case ErrCodeTransferCancelled:
this.errorTitle = TRANSFER_CANCELLED;
this.error = YOU_HAVE_CANCELLED_THE_TRANSFER;
break;
case ErrCodeTransferCancelledByReceiver:
this.errorTitle = TRANSFER_CANCELLED_INTERRUPTED;
this.error = EITHER_THE_TRANSFER_WAS_CANCELLED_BY;
break;
case ErrCodeWrongCode:
this.errorTitle = OOPS;
this.error = THE_RECEIVER_HAS_ENTERED_THE_WRONG_CODE;
break;
case ErrCodeSendTextError:
this.errorTitle = SOMETHING_WENT_WRONG;
// TODO: map error to user friendly name (case invalid nameplate)
break;
case ErrCodeSendFileError:
this.errorTitle = SOMETHING_WENT_WRONG;
// TODO: map error to user friendly name (case invalid nameplate)
break;
case ErrCodeConnectionRefused:
this.errorTitle = OOPS;
this.error = ERR_CONNECTION_REFUSED;
break;
default:
this.errorTitle = SOMETHING_WENT_WRONG;
// TODO: map error to user friendly name (case invalid nameplate)
break;
}
}
});

throw error;
});
});
}, onError: defaultErrorHandler);
}, onError: defaultErrorHandler);
}

Widget widgetByState(
Expand Down Expand Up @@ -197,7 +197,6 @@ class SendSharedState extends ChangeNotifier {
selectingFile = true;
});
await getFilePicker().showSelectFile().onError((error, stackTrace) {
print(error);
throw error!;
}).then((file) async {
await send(file);
Expand Down