Example #1
0
        protected HttpResponseMessage GetResponseByException(HttpActionExecutedContext context)
        {
            string description;
            var    code = ErrorManager.GetErrorCodeByException(context.Exception, out description);

            if (code == GameApiErrorCode.SystemError)
            {
                Log.LogError(description, context.Exception);
            }
            else
            {
                Log.LogWarn(description);
            }

            var returnType = GetReturnType(context);

            if (returnType != null)
            {
                if (typeof(IGameApiErrorDetails).IsAssignableFrom(returnType) &&
                    returnType.GetConstructor(Type.EmptyTypes) != null)
                {
                    var error = (IGameApiErrorDetails)Activator.CreateInstance(returnType);
                    error.ErrorCode        = code;
                    error.ErrorDescription = description;

                    return(context.Request.CreateResponse(HttpStatusCode.InternalServerError, error));
                }
            }

            return(new HttpResponseMessage(HttpStatusCode.InternalServerError)
            {
                Content =
                    new StringContent(Json.SerializeToString(new BetCommandResponse
                {
                    ErrorCode = code,
                    ErrorDescription = description
                }))
            });
        }