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); } }
private UseCaseResponse <T> SetResult(string errorMessage, UseCaseResponseKind status, IEnumerable <ErrorMessage> errors = null) { ErrorMessage = errorMessage; Status = status; Errors = errors; return(this); }
private IActionResult BuildSuccessResult(object data, UseCaseResponseKind status) { switch (status) { case UseCaseResponseKind.Created: return(new CreatedResult($"{path}", data)); default: return(new OkObjectResult(data)); } }
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 }); }
public UseCaseResponse <T> SetError(string errorMessage, UseCaseResponseKind status, IEnumerable <ErrorMessage> errors = null) { return(SetResult(errorMessage, status, errors)); }