internal static void ExceptionOccured <TResult>(object sender, Exception exception, uint httpStatusCode, ErrorFilterFlags filterFlags, Func <Action <object>, Task <TResult> > retryAction = null, Action <object> successCallback = null, string errorCode = "") where TResult : class { Logger.Initialize(sender.GetType().FullName); Logger.Error(exception); if ((filterFlags & ErrorFilterFlags.DisableErrorHandling) == ErrorFilterFlags.DisableErrorHandling) { return; } if (_errorOccuredCallback == null) { return; } exception = GetExceptionOverridden(exception, httpStatusCode); ErrorDescriber desc = _knownErrors.FirstOrDefault(item => item.ExceptionType == exception.GetType()); ErrorDescriber errorDescription = desc ?? new ErrorDescriber(exception.GetType(), typeof(Dialog), ErrorFilterFlags.EnableErrorHandling); if ((filterFlags & errorDescription.FilterFlag) == errorDescription.FilterFlag) { return; } errorDescription.ErrorCode = errorCode; errorDescription.HttpStatusCode = httpStatusCode; if (retryAction != null) { if (successCallback != null) { errorDescription.SuccessCallback = successCallback; errorDescription.RetryAction = async x => { var result = await retryAction(successCallback); successCallback(result); }; } } _errorOccuredCallback(errorDescription); }
public static void RegisterExpectedError(object sender, ErrorDescriber errorDescription) { _knownErrors = _knownErrors.Where(item => item.ExceptionType != errorDescription.ExceptionType).ToList(); _knownErrors.Add(errorDescription); }