Esempio n. 1
0
        private static int GetStatusCode(CenturyError centuryError)
        {
            switch (centuryError.Codigo)
            {
            case CenturyError.TipoError.NoEncontrado:
                return(StatusCodes.Status404NotFound);

            default:
                return(StatusCodes.Status500InternalServerError);
            }
        }
Esempio n. 2
0
        private static Task HandleExceptionAsync(HttpContext context, object ex)
        {
            CenturyError centuryError;
            var          exception = (Exception)ex;

            if (ex.GetType() == typeof(CenturyException))
            {
                centuryError = ((CenturyException)ex).CenturyError;
            }
            else
            {
                centuryError = new CenturyError(CenturyError.TipoError.NoControlada,
                                                exception.Message,
                                                string.Empty);
            }

            var result = JsonConvert.SerializeObject(new { error = centuryError, stacktrace = exception.StackTrace });

            context.Response.ContentType = "application/json";
            context.Response.StatusCode  = GetStatusCode(centuryError);
            return(context.Response.WriteAsync(result));
        }
Esempio n. 3
0
 /// <summary>
 /// ApiResponse Constructor
 /// </summary>
 /// <param name="error"></param>
 /// <param name="stackTrace"></param>
 public ApiResponse(CenturyError error, string stackTrace = null)
 {
     Error      = error;
     StackTrace = stackTrace;
 }