public void OnError(IApiError error) { if (_scene.IsLoginOrRegister) { return; } _scene.GoToStart(); _state.User = null; _state.State = null; }
public object Invoke(MethodInfo methodInfo, object arguments, Func <object> method) { Type returnType = methodInfo.ReturnType; IApiResponse response = (IApiResponse)Activator.CreateInstance(returnType); try { IApiResult result = response as IApiResult; if (result != null) { result.Data = method.Invoke(); } else { method.Invoke(); } response.IsSuccess = true; return(response); } catch (ValidationException exception) { response.ValidationErrors = exception.Errors; } catch (BusinessException exception) { response.ErrorMessage = exception.Message; IApiError error = response as IApiError; if (error != null) { error.ErrorCode = exception.Code; } } catch (Exception exception) { response.ErrorMessage = exception.Message; IBusinessException businessException = exception as IBusinessException; if (businessException != null) { IApiError error = response as IApiError; if (error != null) { error.ErrorCode = businessException.Code; } } } response.IsSuccess = false; return(response); }
private static string GetDetailedErrorMessage(int statusCode, IApiError error) { var baseMessage = $"{error.ErrorSummary} ({statusCode}, {error.ErrorCode})"; var hasErrorCauses = error?.ErrorCauses?.Any() ?? false; if (!hasErrorCauses) { return(baseMessage); } var causes = string.Join(", ", error.ErrorCauses.Select(x => $"{x.ErrorSummary}")); return($"{baseMessage}: {causes}"); }
public async Task Advise(MethodAsyncAdviceContext context) { MethodInfo methodInfo = (MethodInfo)context.TargetMethod; Type returnType = methodInfo.ReturnType.GetGenericArguments()[0]; IApiResponse response; try { await context.ProceedAsync(); return; } catch (ValidationException exception) { response = (IApiResponse)Activator.CreateInstance(returnType); response.ValidationErrors = exception.Errors; } catch (BusinessException exception) { response = (IApiResponse)Activator.CreateInstance(returnType); response.ErrorMessage = exception.Message; IApiError error = response as IApiError; if (error != null) { error.ErrorCode = exception.Code; } } catch (Exception exception) { response = (IApiResponse)Activator.CreateInstance(returnType); response.ErrorMessage = exception.Message; IBusinessException businessException = exception as IBusinessException; if (businessException != null) { IApiError error = response as IApiError; if (error != null) { error.ErrorCode = businessException.Code; } } } response.IsSuccess = false; context.ReturnValue = Task.FromResult(response); }
public void Advise(MethodAdviceContext context) { MethodInfo methodInfo = (MethodInfo)context.TargetMethod; Type returnType = methodInfo.ReturnType; IApiResponse response; try { context.Proceed(); return; } catch (ValidationException exception) { response = (IApiResponse)Activator.CreateInstance(returnType); response.ValidationErrors = exception.Errors; } catch (BusinessException exception) { response = (IApiResponse)Activator.CreateInstance(returnType); response.ErrorMessage = exception.Message; IApiError error = response as IApiError; if (error != null) { error.ErrorCode = exception.Code; } } catch (Exception exception) { response = (IApiResponse)Activator.CreateInstance(returnType); response.ErrorMessage = exception.Message; IBusinessException businessException = exception as IBusinessException; if (businessException != null) { IApiError error = response as IApiError; if (error != null) { error.ErrorCode = businessException.Code; } } } response.IsSuccess = false; context.ReturnValue = response; }
public static ApiResponse <T> AsError <T>(this IApiError error) { return(new ApiResponse <T>(default, error));
/// <summary> /// Initializes a new instance of the <see cref="OktaApiException"/> class. /// </summary> /// <param name="statusCode">The HTTP status code.</param> /// <param name="error">The error data.</param> public OktaApiException(int statusCode, IApiError error) : base(GetDetailedErrorMessage(statusCode, error), statusCode) { _error = error; }
/// <summary> /// Initializes a new instance of the <see cref="OktaApiException"/> class. /// </summary> /// <param name="statusCode">The HTTP status code.</param> /// <param name="error">The error data.</param> public OktaApiException(int statusCode, IApiError error) : base(message: GetDetailedErrorMessage(statusCode, error)) { StatusCode = statusCode; _error = error; }
public void OnError(IApiError error) { }
public void OnError(IApiError error) { _logger.Error(this, $"Failed: '{error.Message}' ({error.GetType().Name})"); Environment.Exit(-1); }
void OnApiError(IApiError obj) { var message = !string.IsNullOrEmpty(obj.Message) ? obj.Message : obj.GetType().Name; _notice.ScheduleNotice(new NoticeModel(message, _ => _scene.GoToStart())); }
public void OnError(IApiError error) { throw new InvalidOperationException(error.Message); }
public ApiResponse(T result, IApiError error) { Result = result; Error = error; }