-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refine exception detail with i18n (#3042)
#### What type of PR is this? /kind feature /kind api-change /area core /milestone 2.1.x #### What this PR does / why we need it: - Configuring message source location and name enables i18n message resolution. - Simple global error handler. - Refactor some exceptions with `ResponseStatusException` to control what HTTP status and problem detail need to be returned. **TODO** - [x] Add more UTs. #### Which issue(s) this PR fixes: Fixes #3020 #### Special notes for your reviewer: Steps to test: 1. Try to refine `src/main/resources/config/i18n/messages_zh.properties` and switch Browser language with Chinese. 2. Delibrately make a mistake as you wish and see the error tips in console. 3. Try to access one page which doesn't exist and see the rendered result. #### Does this PR introduce a user-facing change? ```release-note 完成系统异常的国际化 ```
- Loading branch information
Showing
50 changed files
with
618 additions
and
720 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 12 additions & 16 deletions
28
src/main/java/run/halo/app/extension/exception/ExtensionException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,26 @@ | ||
package run.halo.app.extension.exception; | ||
|
||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.HttpStatusCode; | ||
import org.springframework.web.server.ResponseStatusException; | ||
|
||
/** | ||
* ExtensionException is the superclass of those exceptions that can be thrown by Extension module. | ||
* | ||
* @author johnniang | ||
*/ | ||
public class ExtensionException extends RuntimeException { | ||
|
||
public ExtensionException() { | ||
} | ||
public class ExtensionException extends ResponseStatusException { | ||
|
||
public ExtensionException(String message) { | ||
super(message); | ||
public ExtensionException(String reason) { | ||
this(reason, null); | ||
} | ||
|
||
public ExtensionException(String message, Throwable cause) { | ||
super(message, cause); | ||
public ExtensionException(String reason, Throwable cause) { | ||
this(HttpStatus.INTERNAL_SERVER_ERROR, reason, cause, null, new Object[] {reason}); | ||
} | ||
|
||
public ExtensionException(Throwable cause) { | ||
super(cause); | ||
protected ExtensionException(HttpStatusCode status, String reason, Throwable cause, | ||
String messageDetailCode, Object[] messageDetailArguments) { | ||
super(status, reason, cause, messageDetailCode, messageDetailArguments); | ||
} | ||
|
||
public ExtensionException(String message, Throwable cause, boolean enableSuppression, | ||
boolean writableStackTrace) { | ||
super(message, cause, enableSuppression, writableStackTrace); | ||
} | ||
|
||
} |
23 changes: 6 additions & 17 deletions
23
src/main/java/run/halo/app/extension/exception/ExtensionNotFoundException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,13 @@ | ||
package run.halo.app.extension.exception; | ||
|
||
public class ExtensionNotFoundException extends ExtensionException { | ||
|
||
public ExtensionNotFoundException() { | ||
} | ||
|
||
public ExtensionNotFoundException(String message) { | ||
super(message); | ||
} | ||
import org.springframework.http.HttpStatus; | ||
import run.halo.app.extension.GroupVersionKind; | ||
|
||
public ExtensionNotFoundException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
public class ExtensionNotFoundException extends ExtensionException { | ||
|
||
public ExtensionNotFoundException(Throwable cause) { | ||
super(cause); | ||
public ExtensionNotFoundException(GroupVersionKind gvk, String name) { | ||
super(HttpStatus.NOT_FOUND, "Extension " + gvk + "/" + name + " was not found.", | ||
null, null, new Object[] {gvk, name}); | ||
} | ||
|
||
public ExtensionNotFoundException(String message, Throwable cause, boolean enableSuppression, | ||
boolean writableStackTrace) { | ||
super(message, cause, enableSuppression, writableStackTrace); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.