예제 #1
0
        private HttpStatusCode GetErrorHttpStatusCode(UseCaseResponseKind status)
        {
            switch (status)
            {
            case UseCaseResponseKind.Unauthorized:
                return(HttpStatusCode.Unauthorized);

            case UseCaseResponseKind.Forbidden:
                return(HttpStatusCode.Forbidden);

            case UseCaseResponseKind.NotFound:
                return(HttpStatusCode.NotFound);

            case UseCaseResponseKind.BadRequest:
                return(HttpStatusCode.BadRequest);

            case UseCaseResponseKind.OK:
                return(HttpStatusCode.OK);

            case UseCaseResponseKind.Created:
                return(HttpStatusCode.Created);

            case UseCaseResponseKind.Unavailable:
                return(HttpStatusCode.ServiceUnavailable);

            default:
                return(HttpStatusCode.InternalServerError);
            }
        }
예제 #2
0
        private UseCaseResponse <T> SetResult(string errorMessage, UseCaseResponseKind status, IEnumerable <ErrorMessage> errors = null)
        {
            ErrorMessage = errorMessage;
            Status       = status;
            Errors       = errors;

            return(this);
        }
예제 #3
0
        private IActionResult BuildSuccessResult(object data, UseCaseResponseKind status)
        {
            switch (status)
            {
            case UseCaseResponseKind.Created:
                return(new CreatedResult($"{path}", data));

            default:
                return(new OkObjectResult(data));
            }
        }
예제 #4
0
        private ObjectResult BuildError(object data, UseCaseResponseKind status)
        {
            var httpStatus = GetErrorHttpStatusCode(status);

            if (httpStatus == HttpStatusCode.InternalServerError)
            {
                Log.Error($"[ERROR] {path} ({{@data}})", data);
            }

            return(new ObjectResult(data)
            {
                StatusCode = (int)httpStatus
            });
        }
예제 #5
0
 public UseCaseResponse <T> SetError(string errorMessage, UseCaseResponseKind status, IEnumerable <ErrorMessage> errors = null)
 {
     return(SetResult(errorMessage, status, errors));
 }