Skip to content

Commit

Permalink
address code quality changes
Browse files Browse the repository at this point in the history
  • Loading branch information
GordeaS authored and GordeaS committed Mar 18, 2024
1 parent 00eee5f commit 590d733
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void setSetProperties(Properties setProperties) {

public boolean isAuthDisabled() {
final String property = getSetProperties().getProperty(KEY_AUTH_DISABLED);
return Boolean.valueOf(property);
return Boolean.parseBoolean(property);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,45 +20,44 @@
@ControllerAdvice
public class GlobalExceptionHandler extends EuropeanaGlobalExceptionHandler {

I18nService i18nService;
I18nService i18nService;

@Override
protected I18nService getI18nService() {
return i18nService;
}


/**
* Constructor for the initialization of the Exception handler
* @param requestPathMethodService builtin service for path method mapping
* @param i18nService the internationalization service
*/
@Autowired
public GlobalExceptionHandler(RequestPathMethodService requestPathMethodService,
@Qualifier(BeanNames.BEAN_I18N_SERVICE) I18nService i18nService) {
this.requestPathMethodService = requestPathMethodService;
this.i18nService = i18nService;
}

/**
* HttpMessageNotReadableException thrown when the request body is not parsable to the declared input of the handler method
* @param e the exception indicating the request message parsing error
* @param httpRequest the request object
* @return the api response
*/
@ExceptionHandler
public ResponseEntity<EuropeanaApiErrorResponse> handleRequestBodyNotParsableError(HttpMessageNotReadableException e, HttpServletRequest httpRequest) {
HttpStatus responseStatus = HttpStatus.BAD_REQUEST;
EuropeanaApiErrorResponse response = (new EuropeanaApiErrorResponse.Builder(httpRequest, e, stackTraceEnabled()))
.setStatus(responseStatus.value())
.setError(responseStatus.getReasonPhrase())
.setMessage("Invalid request body: " + e.getMessage())
.setSeeAlso(getSeeAlso())
.build();
/**
* Constructor for the initialization of the Exception handler
*
* @param requestPathMethodService builtin service for path method mapping
* @param i18nService the internationalization service
*/
@Autowired
public GlobalExceptionHandler(RequestPathMethodService requestPathMethodService,
@Qualifier(BeanNames.BEAN_I18N_SERVICE) I18nService i18nService) {
this.requestPathMethodService = requestPathMethodService;
this.i18nService = i18nService;
}

return ResponseEntity
.status(responseStatus)
.headers(createHttpHeaders(httpRequest))
.body(response);
}
@Override
protected I18nService getI18nService() {
return i18nService;
}

/**
* HttpMessageNotReadableException thrown when the request body is not parsable to the declared
* input of the handler method
*
* @param e the exception indicating the request message parsing error
* @param httpRequest the request object
* @return the api response
*/
@ExceptionHandler
public ResponseEntity<EuropeanaApiErrorResponse> handleRequestBodyNotParsableError(
HttpMessageNotReadableException e, HttpServletRequest httpRequest) {
HttpStatus responseStatus = HttpStatus.BAD_REQUEST;
EuropeanaApiErrorResponse response =
(new EuropeanaApiErrorResponse.Builder(httpRequest, e, stackTraceEnabled()))
.setStatus(responseStatus.value()).setError(responseStatus.getReasonPhrase())
.setMessage("Invalid request body: " + e.getMessage()).setSeeAlso(getSeeAlso()).build();

return ResponseEntity.status(responseStatus).headers(createHttpHeaders(httpRequest))
.body(response);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import org.springframework.boot.web.error.ErrorAttributeOptions;
import org.springframework.boot.web.servlet.error.ErrorAttributes;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import eu.europeana.api.commons.web.http.HttpHeaders;

Expand All @@ -27,7 +26,6 @@ public UserSetErrorController(ErrorAttributes errorAttributes) {
* @return ,app with default error attributes
*/
@GetMapping(value = "/error", produces = {HttpHeaders.CONTENT_TYPE_JSON_UTF8, HttpHeaders.CONTENT_TYPE_JSONLD})
@ResponseBody
public Map<String, Object> error(final HttpServletRequest request) {
return this.getErrorAttributes(request, ErrorAttributeOptions.defaults());
}
Expand Down

0 comments on commit 590d733

Please sign in to comment.