예제 #1
0
        private CustomErrorResponse CreateError(Exception exception)
        {
            CustomErrorResponse customError = new CustomErrorResponse();

            if (exception is BaseCustomException customException)
            {
                customError.Code       = customException.ErrorCode;
                customError.ObjectType = customException.ObjectType;
                customError.Message    = customException.Message;
                return(customError);
            }

            if (exception is ArgumentNullException)
            {
                customError.Code    = "ArgumentNull";
                customError.Message = exception.Message;
                return(customError);
            }

            if (exception is KeyNotFoundException)
            {
                customError.Code    = "KeyNotFound";
                customError.Message = exception.Message;
                return(customError);
            }

            else
            {
                customError.Code = "Unexpected";
            }

            return(customError);
        }
예제 #2
0
        private async Task HandleExceptionAsync(HttpContext context, Exception exception)
        {
            HttpResponse response = context.Response;

            response.ContentType = "application/json";
            response.StatusCode  = (int)HttpStatusCode.InternalServerError;//For now, decide on different statuscodes for different errors later

            CustomErrorResponse customError = CreateError(exception);

            await response.WriteAsync(JsonConvert.SerializeObject(customError));
        }