public ActionResult FindJournal([FromBody] QueryModel query) { try { // Verifies if the model is valid, if not, returns a bad request response. // the verification is based on the attributes defined in the DTO. if (!ModelState.IsValid) { MicroserviceException badRequestResponse = new MicroserviceException() { ErrorCode = "InternalError", ErrorMessage = "Unable to process request:" + ModelState.Values, ErrorStatus = 400 }; return(BadRequest(badRequestResponse)); } else { var response = _calculatorService.FindJournal(query); return(Ok(response)); } } // Catches and manages all of the server's errors and responds the client with a controlled object. catch (Exception err) { MicroserviceException internalServerErrorResponse = new MicroserviceException() { ErrorCode = "InternalError", ErrorMessage = "An unexpected error condition was triggered which made impossible to fulfill the request. Please try again or contact support" + err.InnerException, ErrorStatus = 500 }; Log.Error($"Calculator::Exception:: {internalServerErrorResponse}"); return(StatusCode(500, internalServerErrorResponse)); } }
public ActionResult Add([FromBody] AdditionModel addends) { try { // Verifies if the model is valid, if not, returns a bad request response. // the verification is based on the attributes defined in the DTO. if (!ModelState.IsValid) { MicroserviceException badRequestResponse = new MicroserviceException() { ErrorCode = "InternalError", ErrorMessage = "Unable to process request:" + ModelState.Count, ErrorStatus = 400 }; return(BadRequest(badRequestResponse)); } else { // Finds the value of the header with the tracking id StringValues trackingId; Request.Headers.TryGetValue("X-Evi-Tracking-Id", out trackingId); var response = _calculatorService.Addition(addends, trackingId); return(Ok(response)); } } // Catches and manages all of the server's errors and responds the client with a controlled object. catch (Exception err) { MicroserviceException internalServerErrorResponse = new MicroserviceException() { ErrorCode = "InternalError", ErrorMessage = "An unexpected error condition was triggered which made impossible to fulfill the request. Please try again or contact support" + err.InnerException, ErrorStatus = 500 }; Log.Error($"Calculator::Exception:: {internalServerErrorResponse}"); return(StatusCode(500, internalServerErrorResponse)); } }