mirror of
https://github.com/esiur/esiur-dart.git
synced 2025-09-29 18:53:19 +00:00
1.2.6
This commit is contained in:
@@ -1,32 +1,29 @@
|
||||
|
||||
import 'ExceptionCode.dart';
|
||||
import 'ErrorType.dart';
|
||||
|
||||
class AsyncException implements Exception
|
||||
{
|
||||
final ErrorType type;
|
||||
final int code;
|
||||
final String message;
|
||||
class AsyncException implements Exception {
|
||||
final ErrorType type;
|
||||
final int code;
|
||||
final String message;
|
||||
|
||||
AsyncException(this.type, this.code, this.message)
|
||||
{
|
||||
AsyncException(this.type, this.code, this.message) {}
|
||||
|
||||
}
|
||||
static toAsyncException(Exception ex) {
|
||||
return ex is AsyncException
|
||||
? ex
|
||||
: new AsyncException(ErrorType.Exception, 0, ex.toString());
|
||||
}
|
||||
|
||||
static toAsyncException(Exception ex)
|
||||
{
|
||||
return ex is AsyncException ? ex
|
||||
: new AsyncException(ErrorType.Exception, 0, ex.toString());
|
||||
}
|
||||
String errMsg() {
|
||||
if (type == ErrorType.Management)
|
||||
return ExceptionCode.values.elementAt(code).toString() +
|
||||
": " +
|
||||
(message ?? "");
|
||||
else
|
||||
return code.toString() + ": " + message;
|
||||
}
|
||||
|
||||
String errMsg() {
|
||||
if (type == ErrorType.Management)
|
||||
return ExceptionCode.values.elementAt(code).toString() + ": " + (message ?? "");
|
||||
else
|
||||
return code.toString() + ": " + message;
|
||||
}
|
||||
|
||||
@override
|
||||
@override
|
||||
String toString() {
|
||||
return errMsg();
|
||||
}
|
||||
|
@@ -89,6 +89,10 @@ class AsyncReply<T> implements Future<T>
|
||||
{
|
||||
_errorCallbacks.add((ex)=>onError());
|
||||
}
|
||||
else if (onError is Function(Object, StackTrace))
|
||||
{
|
||||
_errorCallbacks.add((ex)=>onError(ex, null));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -169,10 +173,17 @@ class AsyncReply<T> implements Future<T>
|
||||
if (_resultReady)
|
||||
return;
|
||||
|
||||
_exception = AsyncException.toAsyncException(exception);
|
||||
if (exception is AsyncException)
|
||||
_exception = exception;
|
||||
else
|
||||
_exception = AsyncException.toAsyncException(exception);
|
||||
|
||||
///lock (callbacksLock)
|
||||
//{
|
||||
|
||||
if (this._errorCallbacks.length == 0)
|
||||
throw _exception;
|
||||
else
|
||||
_errorCallbacks.forEach((x) {
|
||||
x(_exception);
|
||||
});
|
||||
|
Reference in New Issue
Block a user