use of org.springframework.http.HttpStatus in project FP-PSP-SERVER by FundacionParaguaya.
the class ExceptionTranslatorAdvice method handleGeneralUncaughtExcption.
/**
* <p>
* Any other unhandled exceptions are processed here.
* </p>
* <p>
* We also process user defined (non standard) exceptions annotated with @ResponseStatus.
* See {@link py.org.fundacionparaguaya.pspserver.common.exceptions.UnknownResourceException}
* </p>
* @param ex
* @return
*/
@ExceptionHandler(Exception.class)
protected ResponseEntity<Object> handleGeneralUncaughtExcption(Exception ex) {
HttpStatus status;
ErrorDTO errorDto;
ResponseStatus responseStatus = AnnotationUtils.findAnnotation(ex.getClass(), ResponseStatus.class);
if (responseStatus != null) {
status = responseStatus.value();
errorDto = ErrorDTO.of(responseStatus.reason(), ex.getLocalizedMessage()).formatWithCode();
} else {
status = HttpStatus.INTERNAL_SERVER_ERROR;
errorDto = ErrorDTO.of(ErrorCodes.INTERNAL_SERVER_ERROR.getMessage(), ex.getLocalizedMessage()).formatWithCode();
}
LOG.error("Error id: {}", errorDto.getErrorId());
LOG.error(ex.getMessage(), ex);
return generateResponseEntity(errorDto, status);
}
use of org.springframework.http.HttpStatus in project components by Talend.
the class RuntimeControllerImpl method doValidateDatastoreConnection.
private ResponseEntity<ValidationResultsDto> doValidateDatastoreConnection(DatastoreProperties properties) {
DatastoreDefinition<DatastoreProperties> definition = propertiesHelpers.getFirstDefinitionFromProperties(properties);
try (SandboxedInstance instance = RuntimeUtil.createRuntimeClass(definition.getRuntimeInfo(properties), properties.getClass().getClassLoader())) {
DatastoreRuntime<DatastoreProperties> datastoreRuntime = (DatastoreRuntime) instance.getInstance();
datastoreRuntime.initialize(null, properties);
Iterable<ValidationResult> healthChecks = datastoreRuntime.doHealthChecks(null);
ValidationResultsDto response = new ValidationResultsDto(healthChecks == null ? emptyList() : newArrayList(healthChecks));
HttpStatus httpStatus = response.getStatus() == ValidationResult.Result.OK ? HttpStatus.OK : HttpStatus.BAD_REQUEST;
return new ResponseEntity<>(response, httpStatus);
}
}
use of org.springframework.http.HttpStatus in project crnk-framework by crnk-project.
the class CrnkErrorController method errorToJsonApi.
// TODO for whatever reason this is not called directly
@RequestMapping(produces = HttpHeaders.JSONAPI_CONTENT_TYPE)
@ResponseBody
public ResponseEntity<Document> errorToJsonApi(HttpServletRequest request) {
Map<String, Object> body = getErrorAttributes(request, isIncludeStackTrace(request, MediaType.ALL));
HttpStatus status = getStatus(request);
ErrorDataBuilder errorDataBuilder = ErrorData.builder();
for (Map.Entry<String, Object> attribute : body.entrySet()) {
if (attribute.getKey().equals("status")) {
errorDataBuilder.setStatus(attribute.getValue().toString());
} else if (attribute.getKey().equals("error")) {
errorDataBuilder.setTitle(attribute.getValue().toString());
} else if (attribute.getKey().equals("message")) {
errorDataBuilder.setDetail(attribute.getValue().toString());
} else {
errorDataBuilder.addMetaField(attribute.getKey(), attribute.getValue());
}
}
Document document = new Document();
document.setErrors(Arrays.asList(errorDataBuilder.build()));
return new ResponseEntity<>(document, status);
}
use of org.springframework.http.HttpStatus in project tutorials by eugenp.
the class EmployeeRestController method createEmployee.
@PostMapping("/employees")
public ResponseEntity<Employee> createEmployee(@RequestBody Employee employee) {
HttpStatus status = HttpStatus.CREATED;
Employee saved = employeeService.save(employee);
return new ResponseEntity<>(saved, status);
}
use of org.springframework.http.HttpStatus in project tutorials by eugenp.
the class StepDefsIntegrationTest method the_client_receives_status_code_of.
@Then("^the client receives status code of (\\d+)$")
public void the_client_receives_status_code_of(int statusCode) throws Throwable {
final HttpStatus currentStatusCode = latestResponse.getTheResponse().getStatusCode();
assertThat("status code is incorrect : " + latestResponse.getBody(), currentStatusCode.value(), is(statusCode));
}
Aggregations