Exemple #1
0
        public override async Task OnExceptionAsync(ExceptionContext context)
        {
            var exception = context.Exception;

            if (exception != null)
            {
                await TraceException(exception);

                var errorCode = UCenterErrorCode.InternalHttpServerError;

                if (context.Exception is UCenterException)
                {
                    errorCode = (context.Exception as UCenterException).ErrorCode;
                }
                else if (context.Exception is MongoException)
                {
                    errorCode = UCenterErrorCode.InternalDatabaseError;
                }

                string errorMessage = context.Exception.Message;

                var content = new UCenterResponse <UCenterError>
                {
                    Status = UCenterResponseStatus.Error,
                    Error  = new UCenterError {
                        ErrorCode = errorCode, Message = errorMessage
                    }
                };

                context.Result = new JsonResult(content);
            }
        }
Exemple #2
0
        //-------------------------------------------------------------------------
        bool _checkResponse <TResponse>(WWW www, Action <UCenterResponseStatus, TResponse, UCenterError> handler)
        {
            if (www != null)
            {
                if (www.isDone)
                {
                    UCenterResponse <TResponse> response = null;

                    if (string.IsNullOrEmpty(www.error))
                    {
                        try
                        {
                            response = EbTool.jsonDeserialize <UCenterResponse <TResponse> >(www.text);
                        }
                        catch (Exception ex)
                        {
                            EbLog.Error("ClientUCenterSDK.update() UCenterResponse Error");
                            EbLog.Error(ex.ToString());
                        }
                    }
                    else
                    {
                        EbLog.Error(www.url);
                        EbLog.Error(www.error);
                    }

                    www = null;

                    if (handler != null)
                    {
                        if (response != null)
                        {
                            handler(response.Status, response.Result, response.Error);
                        }
                        else
                        {
                            var error = new UCenterError();
                            error.ErrorCode = UCenterErrorCode.ServiceUnavailable;
                            error.Message   = "";
                            handler(UCenterResponseStatus.Error, default(TResponse), error);
                        }

                        handler = null;
                    }

                    return(true);
                }
            }

            return(false);
        }
Exemple #3
0
        private HttpResponseMessage CreateErrorResponseMessage(UCenterErrorCode errorCode, string errorMessage)
        {
            var response = new HttpResponseMessage(HttpStatusCode.OK);
            var content  = new UCenterResponse <UCenterError>
            {
                Status = UCenterResponseStatus.Error,
                Error  = new UCenterError {
                    ErrorCode = errorCode, Message = errorMessage
                }
            };

            response.Content = new ObjectContent <UCenterResponse <UCenterError> >(content, new JsonMediaTypeFormatter());

            return(response);
        }