Ejemplo n.º 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);
            }
        }
Ejemplo n.º 2
0
        private UseCaseResponse <T> SetResult(string errorMessage, UseCaseResponseKind status, IEnumerable <ErrorMessage> errors = null)
        {
            ErrorMessage = errorMessage;
            Status       = status;
            Errors       = errors;

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

            default:
                return(new OkObjectResult(data));
            }
        }
Ejemplo n.º 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
            });
        }
Ejemplo n.º 5
0
 public UseCaseResponse <T> SetError(string errorMessage, UseCaseResponseKind status, IEnumerable <ErrorMessage> errors = null)
 {
     return(SetResult(errorMessage, status, errors));
 }