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

Handle the possible different exceptions when an application tries to establish a session but an error is thrown #12

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ class BleWifiBloc extends Bloc<BleWifiEvent, BleWifiState> {
emit(BleWifiEstablishedConnectionFailedState());
case EstablishSessionStatus.keymismatch:
emit(BleWifiEstablishedConnectionKeyMismatch());
case EstablishSessionStatus.bufferlengtherror:
// TODO: Handle this case.
case EstablishSessionStatus.unexpectedstate:
// TODO: Handle this case.
case EstablishSessionStatus.unknownerror:
// TODO: Handle this case.
}
});

Expand Down
20 changes: 19 additions & 1 deletion lib/src/esp_prov.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ enum EstablishSessionStatus {
connected,
disconnected,
keymismatch,
// TODO: review this values in the PR
bufferlengtherror,
unexpectedstate,
unknownerror
}

class EspProv {
Expand All @@ -41,7 +45,21 @@ class EspProv {
return EstablishSessionStatus.disconnected;
} catch (e) {
if (await transport.checkConnect()) {
return EstablishSessionStatus.keymismatch;
// TODO: review how to handle the possible errors.
// TODO: confirm the possible errors with flutter_ble_lib_ios_15 and flutter_blue_plus
// * It is just a possible way to handle the errors.
// * The ideal would be to have some standardized response to catch the exceptions,
// * But it must be confirmed.
String errorMessage = e.toString();
if (errorMessage.contains('Unexpected state')) {
return EstablishSessionStatus.unexpectedstate;
} else if (errorMessage.contains('Key mismatch')) {
return EstablishSessionStatus.keymismatch;
} else if (errorMessage.contains('Empty response')) {
return EstablishSessionStatus.bufferlengtherror;
} else {
return EstablishSessionStatus.unknownerror;
}
} else {
debugPrint('-----------------------');
debugPrint('EstablishSession Error:');
Expand Down