Skip to content

Commit

Permalink
SonarCloud bugfix #54
Browse files Browse the repository at this point in the history
  • Loading branch information
tillias committed Oct 26, 2020
1 parent 9170efb commit 0b54932
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ private String resolvePathPrefix() {
public CorsFilter corsFilter() {
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
CorsConfiguration config = jHipsterProperties.getCors();
if (config.getAllowedOrigins() != null && !config.getAllowedOrigins().isEmpty()) {
List<String> allowedOrigins = config.getAllowedOrigins();
if (allowedOrigins != null && !allowedOrigins.isEmpty()) {
log.debug("Registering CORS filter");
source.registerCorsConfiguration("/api/**", config);
source.registerCorsConfiguration("/management/**", config);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,18 @@ public ResponseEntity<Problem> process(@Nullable ResponseEntity<Problem> entity,
if (!(problem instanceof ConstraintViolationProblem || problem instanceof DefaultProblem)) {
return entity;
}

ProblemBuilder builder = Problem.builder()
.withType(Problem.DEFAULT_TYPE.equals(problem.getType()) ? ErrorConstants.DEFAULT_TYPE : problem.getType())
.withStatus(problem.getStatus())
.withTitle(problem.getTitle())
.with(PATH_KEY, request.getNativeRequest(HttpServletRequest.class).getRequestURI());
.withTitle(problem.getTitle());

HttpServletRequest nativeRequest = request.getNativeRequest(HttpServletRequest.class);
if (nativeRequest != null) {
builder.with(PATH_KEY, nativeRequest.getRequestURI());
} else {
builder.with(PATH_KEY, "Error: unknown URI");
}

if (problem instanceof ConstraintViolationProblem) {
builder
Expand Down Expand Up @@ -110,13 +117,13 @@ public ResponseEntity<Problem> handleMethodArgumentNotValid(MethodArgumentNotVal
@ExceptionHandler
public ResponseEntity<Problem> handleEmailAlreadyUsedException(com.github.microcatalog.service.EmailAlreadyUsedException ex, NativeWebRequest request) {
EmailAlreadyUsedException problem = new EmailAlreadyUsedException();
return create(problem, request, HeaderUtil.createFailureAlert(applicationName, true, problem.getEntityName(), problem.getErrorKey(), problem.getMessage()));
return create(problem, request, HeaderUtil.createFailureAlert(applicationName, true, problem.getEntityName(), problem.getErrorKey(), problem.getMessage()));
}

@ExceptionHandler
public ResponseEntity<Problem> handleUsernameAlreadyUsedException(com.github.microcatalog.service.UsernameAlreadyUsedException ex, NativeWebRequest request) {
LoginAlreadyUsedException problem = new LoginAlreadyUsedException();
return create(problem, request, HeaderUtil.createFailureAlert(applicationName, true, problem.getEntityName(), problem.getErrorKey(), problem.getMessage()));
return create(problem, request, HeaderUtil.createFailureAlert(applicationName, true, problem.getEntityName(), problem.getErrorKey(), problem.getMessage()));
}

@ExceptionHandler
Expand All @@ -140,7 +147,7 @@ public ResponseEntity<Problem> handleConcurrencyFailure(ConcurrencyFailureExcept

@Override
public ProblemBuilder prepare(final Throwable throwable, final StatusType status, final URI type) {

Collection<String> activeProfiles = Arrays.asList(env.getActiveProfiles());

if (activeProfiles.contains(JHipsterConstants.SPRING_PROFILE_PRODUCTION)) {
Expand All @@ -155,7 +162,7 @@ public ProblemBuilder prepare(final Throwable throwable, final StatusType status
.map(this::toProblem)
.orElse(null));
}

if (throwable instanceof DataAccessException) {
return Problem.builder()
.withType(type)
Expand All @@ -167,7 +174,7 @@ public ProblemBuilder prepare(final Throwable throwable, final StatusType status
.map(this::toProblem)
.orElse(null));
}

if (containsPackageName(throwable.getMessage())) {
return Problem.builder()
.withType(type)
Expand Down

0 comments on commit 0b54932

Please sign in to comment.