How to catch exception on publish?
SimonVillage opened this issue · comments
My publish response is throwing an exception. I am trying to catch the exception but it doesn't work:
try {
subscription.publish(data);
} catch (e) {
print(e);
}
[VERBOSE-2:ui_dart_state.cc(209)] Unhandled Exception: Error{code: 0, message: Points already collected within 24h}
#0 Transport._processResult
package:centrifuge/src/transport.dart:148
#1 Transport.sendMessage
package:centrifuge/src/transport.dart:95
<asynchronous suspension>
#2 ClientImpl.publish
package:centrifuge/src/client.dart:183
<asynchronous suspension>
I return the error like this on my backend:
{ error: { message: e.message } }
I wonder if it would be better to not return an error but something like a custom error to now have it convert into an exception? Something like
{ result: { data: { success: false, message: "Foo" } } };
try {
subscription.publish(data);
} on Error catch (e) {
print(e);
}
You have to define on Error
then it will work. Would be better to have a different naming like CentrifugeError
. I will close this issue anyways.