Ejemplo n.º 1
0
 public RestBusinessError(RestErrorType errorType, Exception ex)
 {
     ErrorType = errorType;
     if (ex != null)
     {
         Message = ex.Message;
         Details = ex.ToString();
     }
 }
        private async Task HandleExceptionAsync(HttpContext context, IHostEnvironment env, Exception exception)
        {
            const RestErrorType errorType = RestErrorType.SystemException;
            var errorCode  = string.Empty;
            var message    = exception.Message + exception.InnerException?.Message;
            var stackTrace = env.IsDevelopment() || env.IsStaging() ? exception.StackTrace : string.Empty;

            var error = new RestError((int)errorType, message, errorCode, stackTrace);

            error = HandleCustomException(error, context, env, exception);

            var response = new RestResponse <object>(error);

            var result = JsonConvert.SerializeObject(response);

            context.Response.ContentType = "application/json";
            context.Response.StatusCode  = (int)HttpStatusCode.OK;
            await context.Response.WriteAsync(result);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Given a REST error, returns the corresponding HTTP code.
 /// </summary>
 public static HttpStatusCode ToHttpStatusCode(this RestErrorType tipoResultado)
 {
     return(errorStatusCodeMapping[tipoResultado]);
 }
Ejemplo n.º 4
0
 public RestBusinessError(RestErrorType errorType, string message)
     : this(errorType, message, message)
 {
 }
Ejemplo n.º 5
0
 public RestBusinessError(RestErrorType errorType, string message, string details)
 {
     ErrorType = errorType;
     Message   = message;
     Details   = details;
 }
Ejemplo n.º 6
0
 public RestBusinessError(RestErrorType errorType)
     : this(errorType, string.Empty, string.Empty)
 {
 }