Skip to content

Commit

Permalink
feat: edit locale
Browse files Browse the repository at this point in the history
  • Loading branch information
ray-yhc committed Oct 19, 2023
1 parent 9ca9f4c commit 05ba80d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
8 changes: 7 additions & 1 deletion API-Server/src/main/java/swm/hkcc/LGTM/LgtmApplication.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
package swm.hkcc.LGTM;

import jakarta.annotation.PostConstruct;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;

import java.util.Locale;
import java.util.TimeZone;

@ConfigurationPropertiesScan
@SpringBootApplication
public class LgtmApplication {
@PostConstruct
public void started() {
TimeZone.setDefault(TimeZone.getTimeZone("Asia/Seoul"));
Locale.setDefault(Locale.KOREA);
}

public static void main(String[] args) {
SpringApplication.run(LgtmApplication.class, args);
Locale.setDefault(Locale.KOREA);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,24 @@ protected ResponseEntity<Object> handleMethodArgumentNotValid(MethodArgumentNotV
Sentry.captureException(e);
StringBuilder sb = new StringBuilder();

// request info
sb.append("request endpoint ").append(request.getDescription(false)).append(" ");

// field errors info
Set<FieldError> fieldErrors = new HashSet<>(e.getBindingResult().getFieldErrors());
fieldErrors
.forEach(error -> {
sb.append("\n[").append(error.getField()).append(" : ").append(error.getDefaultMessage()).append("]");
sb.append(error.getField()).append(" : ").append(error.getDefaultMessage()).append("\n");
});
// other errors info
e.getBindingResult().getAllErrors()
.stream()
.filter(error -> !fieldErrors.contains(error))
.forEach(error -> {
sb.append("\n[").append(error.getDefaultMessage()).append("]");
sb.append(error.getDefaultMessage()).append("\n");
});

// request info
sb.append("(").append(request.getDescription(false)).append(")");


GeneralException ge = new GeneralException(ResponseCode.VALIDATION_ERROR, sb.toString(), e.getCause());
return handleExceptionInternal(ge, ge.getResponseCode(), request);
}
Expand Down

0 comments on commit 05ba80d

Please sign in to comment.