예제 #1
0
        public async Task <ApiResponse> ProcessRequest(ApiRequest request)
        {
            _userId = request.UserId;
            try
            {
                await WriteLogRequest(request);

                if (String.IsNullOrEmpty(request.Path))
                {
                    throw new ArgumentOutOfRangeException("Invalid path");
                }

                var cmd = ApiV2RequestModel.GetCommand(_appReader, request.Path);

                if (cmd.DebugOnly && !_host.IsDebugConfiguration)
                {
                    throw new ArgumentOutOfRangeException("Invalid environment");
                }

                cmd.ValidateRequest(request);

                var handler = cmd.GetHandler(ServiceLocator.Current);

                var resp = await handler.ExecuteAsync(request);
                await WriteLogResponse(resp);

                return(resp);
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null)
                {
                    ex = ex.InnerException;
                }

                await WriteException(request, ex);

                var msg = ex.Message;
                if (msg.StartsWith("API:", StringComparison.OrdinalIgnoreCase))
                {
                    msg = msg.Substring(4);
                }
                else if (!_host.IsDebugConfiguration)
                {
                    msg = "invalid request data";
                }

                return(new ApiResponse()
                {
                    ContentType = MimeTypes.Application.Json,
                    Body = JsonConvert.SerializeObject(new { success = false, error = msg }, JsonHelpers.CompactSerializerSettings)
                });
            }
        }
예제 #2
0
 internal void SetParent(ApiV2RequestModel parent)
 {
     _model = parent;
 }
예제 #3
0
 internal void SetParent(ApiV2RequestModel parent)
 {
     _model = parent;
     SqlCommand?.SetParent(parent);
 }