Skip to content

Commit b7192bf

Browse files
authored
Merge pull request #54 from bnc-projects/july-updates
Updates for July
2 parents 66c2341 + 7bff587 commit b7192bf

File tree

9 files changed

+82
-207
lines changed

9 files changed

+82
-207
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ env:
66
global:
77
- TF_IN_AUTOMATION=1
88
- SERVICE_NAME=spring-boot-java-base
9-
- VERSION=0.12.0
9+
- VERSION=0.12.4
1010
- DEPLOYMENT_ACCESS_KEY_ID=
1111
- DEPLOYMENT_SECRET_ACCESS_KEY=
1212
- AWS_DEFAULT_REGION=

build.gradle

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,12 @@ allprojects {
8181
}
8282

8383
dependencies {
84-
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter', version: '5.4.2'
84+
implementation group: 'com.bnc', name: 'market-data-api', version: '0.0.8'
85+
86+
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter', version: '5.5.0'
8587
testImplementation group: 'org.assertj', name: 'assertj-core', version: '3.12.2'
86-
testImplementation group: 'org.mockito', name: 'mockito-core', version: '2.28.2'
87-
testImplementation group: 'org.mockito', name: 'mockito-junit-jupiter', version: '2.28.2'
88-
testRuntime group: 'org.junit.platform', name: 'junit-platform-launcher', version: '1.4.2'
88+
testImplementation group: 'org.mockito', name: 'mockito-core', version: '3.0.0'
89+
testImplementation group: 'org.mockito', name: 'mockito-junit-jupiter', version: '3.0.0'
8990
}
9091
}
9192

service/build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
plugins {
2-
id "org.springframework.boot" version "2.1.5.RELEASE"
3-
id "io.spring.dependency-management" version "1.0.7.RELEASE"
2+
id "org.springframework.boot" version "2.1.6.RELEASE"
3+
id "io.spring.dependency-management" version "1.0.8.RELEASE"
44
id "com.palantir.docker" version "0.22.1"
55
id "com.gorylenko.gradle-git-properties" version "2.0.0"
66
}
@@ -40,7 +40,7 @@ dependencies {
4040
implementation project(':client')
4141
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-web'
4242
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-actuator'
43-
implementation group: 'org.springframework.cloud', name: 'spring-cloud-starter-sleuth', version: '2.1.1.RELEASE'
44-
implementation group: 'io.micrometer', name: 'micrometer-registry-new-relic', version: '1.1.4'
43+
implementation group: 'org.springframework.cloud', name: 'spring-cloud-starter-sleuth', version: '2.1.2.RELEASE'
44+
implementation group: 'io.micrometer', name: 'micrometer-registry-new-relic', version: '1.2.0'
4545
testImplementation group: 'org.springframework.boot', name: 'spring-boot-starter-test'
4646
}

service/src/main/java/com/bnc/sbjb/model/api/CustomError.java

Lines changed: 0 additions & 56 deletions
This file was deleted.

service/src/main/java/com/bnc/sbjb/model/api/ValidationError.java

Lines changed: 0 additions & 52 deletions
This file was deleted.

service/src/main/java/com/bnc/sbjb/rest/DefaultErrorController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.bnc.sbjb.rest;
22

3-
import com.bnc.sbjb.model.api.CustomError;
3+
import com.bnc.api.model.error.CustomError;
44
import javax.servlet.http.HttpServletResponse;
55
import org.springframework.boot.web.servlet.error.ErrorController;
66
import org.springframework.http.HttpStatus;

service/src/main/java/com/bnc/sbjb/rest/DefaultExceptionHandler.java

Lines changed: 71 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,92 @@
11
package com.bnc.sbjb.rest;
22

3-
import com.bnc.sbjb.model.api.CustomError;
3+
import com.bnc.api.model.error.CustomError;
4+
import com.bnc.api.model.error.ValidationError;
5+
import java.nio.file.AccessDeniedException;
6+
import java.util.ArrayList;
7+
import java.util.List;
8+
import java.util.NoSuchElementException;
9+
import javax.servlet.http.HttpServletRequest;
410
import org.slf4j.Logger;
511
import org.slf4j.LoggerFactory;
612
import org.springframework.http.HttpStatus;
13+
import org.springframework.http.converter.HttpMessageNotReadableException;
14+
import org.springframework.validation.FieldError;
15+
import org.springframework.web.HttpMediaTypeNotSupportedException;
16+
import org.springframework.web.HttpRequestMethodNotSupportedException;
17+
import org.springframework.web.bind.MethodArgumentNotValidException;
718
import org.springframework.web.bind.annotation.ControllerAdvice;
819
import org.springframework.web.bind.annotation.ExceptionHandler;
920
import org.springframework.web.bind.annotation.ResponseBody;
1021
import org.springframework.web.bind.annotation.ResponseStatus;
22+
import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;
1123

1224
@ControllerAdvice
1325
public class DefaultExceptionHandler {
1426

1527
private static final Logger logger = LoggerFactory.getLogger(DefaultExceptionHandler.class);
1628

29+
@ExceptionHandler({NoSuchElementException.class})
30+
@ResponseStatus(HttpStatus.NOT_FOUND)
31+
public void handleExceptionNotFound(final Exception ex) {
32+
logger.debug("Could not find resource", ex);
33+
}
34+
35+
@ExceptionHandler(IllegalArgumentException.class)
36+
@ResponseStatus(HttpStatus.BAD_REQUEST)
37+
@ResponseBody
38+
public CustomError handleIllegalArgumentException(final IllegalArgumentException ex) {
39+
logger.debug("Invalid Argument Received", ex);
40+
return new CustomError(HttpStatus.BAD_REQUEST, "Invalid Argument Received");
41+
}
42+
43+
@ExceptionHandler({
44+
HttpMessageNotReadableException.class,
45+
MethodArgumentTypeMismatchException.class,
46+
HttpMediaTypeNotSupportedException.class})
47+
@ResponseStatus(HttpStatus.BAD_REQUEST)
48+
@ResponseBody
49+
public CustomError handleBadRequests(final Exception ex) {
50+
logger.debug("Bad input from client", ex);
51+
return new CustomError(HttpStatus.BAD_REQUEST, ex.getMessage());
52+
}
53+
54+
@ExceptionHandler(MethodArgumentNotValidException.class)
55+
@ResponseStatus(code = HttpStatus.BAD_REQUEST)
56+
@ResponseBody
57+
public CustomError handleMethodArgumentNotValid(MethodArgumentNotValidException ex) {
58+
CustomError errors = new CustomError(HttpStatus.BAD_REQUEST, "Validation Error");
59+
List<ValidationError> subErrors = new ArrayList<>();
60+
if (ex.getBindingResult().getFieldErrorCount() > 0) {
61+
List<FieldError> fieldErrors = ex.getBindingResult().getFieldErrors();
62+
for (FieldError fieldError : fieldErrors) {
63+
subErrors.add(new ValidationError(fieldError.getObjectName().replace("Dto", ""), fieldError.getField(),
64+
fieldError.getRejectedValue(), fieldError.getDefaultMessage()));
65+
}
66+
}
67+
errors.setSubErrors(subErrors);
68+
return errors;
69+
}
70+
71+
@ExceptionHandler(AccessDeniedException.class)
72+
@ResponseStatus(HttpStatus.FORBIDDEN)
73+
public void handleAccessDenied(AccessDeniedException ex) {
74+
logger.debug("Access Denied", ex);
75+
}
76+
77+
@ExceptionHandler({HttpRequestMethodNotSupportedException.class})
78+
@ResponseStatus(HttpStatus.METHOD_NOT_ALLOWED)
79+
@ResponseBody
80+
public CustomError handleExceptionMethodNotAllowed(final Exception ex) {
81+
logger.debug("Method not allowed", ex);
82+
return new CustomError(HttpStatus.METHOD_NOT_ALLOWED, "HTTP Method not allowed");
83+
}
84+
1785
@ExceptionHandler(Exception.class)
1886
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
1987
@ResponseBody
20-
public CustomError handleException(Exception ex) {
21-
logger.error("Unknown exception errorMessage=\"{}\"]", ex.getMessage(), ex);
88+
public CustomError handleException(HttpServletRequest httpServletRequest, Exception ex) {
89+
logger.error("Unknown exception [queryString=\"{}\" errorMessage=\"{}\"]", httpServletRequest.getQueryString(), ex.getMessage(), ex);
2290
return new CustomError(HttpStatus.INTERNAL_SERVER_ERROR,
2391
"Oops something went wrong. Please contact us if this keeps occurring.");
2492
}

service/src/test/java/com/bnc/sbjb/model/api/CustomErrorTest.java

Lines changed: 0 additions & 46 deletions
This file was deleted.

service/src/test/java/com/bnc/sbjb/model/api/ValidationErrorTest.java

Lines changed: 0 additions & 40 deletions
This file was deleted.

0 commit comments

Comments
 (0)