コード例 #1
0
        /// <summary>
        /// Creates the error response from the values provided.
        /// 
        /// If the errorCode is empty it will use the first validation error code, 
        /// if there is none it will throw an error.
        /// </summary>
        /// <param name="errorCode">The error code.</param>
        /// <param name="errorMessage">The error message.</param>
        /// <param name="validationErrors">The validation errors.</param>
        /// <returns></returns>
        public static ResponseStatus CreateResponseStatus(string errorCode, string errorMessage, IEnumerable<ValidationErrorField> validationErrors)
        {
            var to = new ResponseStatus {
                ErrorCode = errorCode,
                Message = errorMessage,
                Errors = new List<ResponseError>(),
            };
            if (validationErrors != null)
            {
                foreach (var validationError in validationErrors)
                {
                    var error = new ResponseError {
                        ErrorCode = validationError.ErrorCode,
                        FieldName = validationError.FieldName,
                        Message = validationError.ErrorMessage,
                        Meta = validationError.Meta,
                    };
                    to.Errors.Add(error);

                    if (IsNullOrEmpty(to.ErrorCode))
                    {
                        to.ErrorCode = validationError.ErrorCode;
                    }
                    if (IsNullOrEmpty(to.Message))
                    {
                        to.Message = validationError.ErrorMessage;
                    }
                }
            }

            if (IsNullOrEmpty(errorCode) && IsNullOrEmpty(to.ErrorCode))
                throw new ArgumentException("Cannot create a valid error response with a en empty errorCode and an empty validationError list");

            return to;
        }
コード例 #2
0
ファイル: DtoUtils.cs プロジェクト: rudygt/ServiceStack
        public static object CreateErrorResponse(object request, Exception ex, ResponseStatus responseStatus)
        {
            var responseDto = CreateResponseDto(request, responseStatus);

            var httpError = ex as IHttpError;
            if (httpError != null)
            {
                if (responseDto != null)
                    httpError.Response = responseDto;

                return httpError;
            }

            var errorCode = ex.GetType().Name;
            var errorMsg = ex.Message;
            if (responseStatus != null)
            {
                errorCode = responseStatus.ErrorCode ?? errorCode;
                errorMsg = responseStatus.Message ?? errorMsg;
            }

            return new HttpError(responseDto, ex.ToStatusCode(), errorCode, errorMsg, ex);
        }
コード例 #3
0
 public ServiceResponseException(ResponseStatus responseStatus)
     : base(GetErrorMessage(responseStatus.ErrorCode, responseStatus.Message))
 {
     this.ErrorCode = responseStatus.ErrorCode;
 }
コード例 #4
0
        public virtual void OnExceptionTypeFilter(Exception ex, ResponseStatus responseStatus)
        {
            var argEx = ex as ArgumentException;
            var isValidationSummaryEx = argEx is ValidationException;
            if (argEx != null && !isValidationSummaryEx && argEx.ParamName != null)
            {
                var paramMsgIndex = argEx.Message.LastIndexOf("Parameter name:", StringComparison.Ordinal);
                var errorMsg = paramMsgIndex > 0
                    ? argEx.Message.Substring(0, paramMsgIndex)
                    : argEx.Message;

                if (responseStatus.Errors == null)
                    responseStatus.Errors = new List<ResponseError>();

                responseStatus.Errors.Add(new ResponseError
                {
                    ErrorCode = ex.GetType().Name,
                    FieldName = argEx.ParamName,
                    Message = errorMsg,
                });
                return;
            }

            var serializationEx = ex as SerializationException;
            if (serializationEx != null)
            {
                var errors = serializationEx.Data["errors"] as List<RequestBindingError>;
                if (errors != null)
                {
                    if (responseStatus.Errors == null)
                        responseStatus.Errors = new List<ResponseError>();

                    responseStatus.Errors = errors.Select(e => new ResponseError
                    {
                        ErrorCode = ex.GetType().Name,
                        FieldName = e.PropertyName,
                        Message = e.PropertyValueString != null ? "'{0}' is an Invalid value for '{1}'".Fmt(e.PropertyValueString, e.PropertyName) : "Invalid Value for '{0}'".Fmt(e.PropertyName)
                    }).ToList();
                }
            }
        }
コード例 #5
0
 public GameResponse()
 {
     ResponseStatus = new ResponseStatus();
 }
コード例 #6
0
 public ProcessRequestResponse()
 {
     ResponseStatus = new ResponseStatus();
 }
コード例 #7
0
ファイル: Default.aspx.cs プロジェクト: permadiwibisono/Test
 private void ShowIfError(ResponseStatus status, string field, Literal lit)
 {
     var fieldError = status.Errors.FirstOrDefault(x => field.EqualsIgnoreCase(x.FieldName));
     lit.Text = fieldError != null 
         ? "<span class='error'> - {0}</span>".Fmt(fieldError.Message ?? fieldError.ErrorCode)
         : "";
 }
 protected ResponseBase()
 {
     ResponseStatus = new ResponseStatus();
 }
コード例 #9
0
 public string errorResponse(ScriptScopeContext scope, ResponseStatus errorStatus, string fieldName) =>
 ViewUtils.ErrorResponse(errorStatus, fieldName);
コード例 #10
0
 public string errorResponseSummary(ScriptScopeContext scope, ResponseStatus errorStatus) =>
 ViewUtils.ErrorResponseSummary(errorStatus);
コード例 #11
0
ファイル: HttpError.cs プロジェクト: lonelyong/ServiceStack
 public HttpError(ResponseStatus responseStatus, HttpStatusCode statusCode)
     : this(new ErrorResponse {
     ResponseStatus = responseStatus
 }, statusCode, responseStatus.ErrorCode, responseStatus.Message)
 {
 }
コード例 #12
0
 public CrawlersResponse()
 {
     ResponseStatus = new ResponseStatus();
 }
コード例 #13
0
 public SeasonStatusResponse()
 {
     ResponseStatus = new ResponseStatus();
 }
コード例 #14
0
 public DivisionsResponse()
 {
     ResponseStatus = new ResponseStatus();
 }
コード例 #15
0
 public ServiceResponseException(ResponseStatus responseStatus)
     : base(GetErrorMessage(responseStatus.ErrorCode, responseStatus.Message))
 {
     this.ErrorCode = responseStatus.ErrorCode;
 }
コード例 #16
0
ファイル: HostContext.cs プロジェクト: tystol/ServiceStack
 public static void OnExceptionTypeFilter(Exception exception, ResponseStatus responseStatus)
 {
     AssertAppHost().OnExceptionTypeFilter(exception, responseStatus);
 }
コード例 #17
0
ファイル: DtoUtils.cs プロジェクト: rudygt/ServiceStack
        /// <summary>
        /// Create an instance of the service response dto type and inject it with the supplied responseStatus
        /// </summary>
        /// <param name="request"></param>
        /// <param name="responseStatus"></param>
        /// <returns></returns>
        public static object CreateResponseDto(object request, ResponseStatus responseStatus)
        {
            // Predict the Response message type name
            var responseDtoType = WebRequestUtils.GetErrorResponseDtoType(request);
            var responseDto = responseDtoType.CreateInstance();
            if (responseDto == null)
                return null;

            // For faster serialization of exceptions, services should implement IHasResponseStatus
            var hasResponseStatus = responseDto as IHasResponseStatus;
            if (hasResponseStatus != null)
            {
                hasResponseStatus.ResponseStatus = responseStatus;
            }
            else
            {
                var responseStatusProperty = responseDtoType.GetProperty(ResponseStatusPropertyName);
                if (responseStatusProperty != null)
                {
                    // Set the ResponseStatus
                    responseStatusProperty.SetProperty(responseDto, responseStatus);
                }
            }

            // Return an Error DTO with the exception populated
            return responseDto;
        }
コード例 #18
0
 public ParticipantStatusResponse()
 {
     ResponseStatus = new ResponseStatus();
 }
コード例 #19
0
        public virtual void OnExceptionTypeFilter(Exception ex, ResponseStatus responseStatus)
        {
            var argEx = ex as ArgumentException;
            var isValidationSummaryEx = argEx is ValidationException;
            if (argEx != null && !isValidationSummaryEx && argEx.ParamName != null)
            {
                var paramMsgIndex = argEx.Message.LastIndexOf("Parameter name:");
                var errorMsg = paramMsgIndex > 0
                    ? argEx.Message.Substring(0, paramMsgIndex)
                    : argEx.Message;

                responseStatus.Errors.Add(new ResponseError
                {
                    ErrorCode = ex.GetType().Name,
                    FieldName = argEx.ParamName,
                    Message = errorMsg,
                });
            }
        }
コード例 #20
0
 public ServersResponse()
 {
     ResponseStatus = new ResponseStatus();
 }