Class ProblemDetailFactory
java.lang.Object
io.leandev.appfuse.error.ProblemDetailFactory
RFC 7807/9457 ProblemDetail 工廠類別
提供建立標準化 ProblemDetail 的工具方法。
RFC 7807 標準欄位對應
type- 問題類型 URI(預設 about:blank)title- 問題標題(HTTP 狀態描述)status- HTTP 狀態碼detail- 問題詳細描述instance- 發生問題的請求路徑
自訂擴充欄位
violations- 驗證錯誤詳情errorCode- 應用程式錯誤代碼format- 訊息模板(用於國際化)params- 訊息參數
-
Method Summary
Modifier and TypeMethodDescriptionstatic org.springframework.http.ProblemDetailaccountDisabled(String detail) 建立帳號停用錯誤static org.springframework.http.ProblemDetailaccountExpired(String detail) 建立帳號過期錯誤static org.springframework.http.ProblemDetailaccountLocked(String detail) 建立帳號鎖定錯誤static org.springframework.http.ProblemDetailbadCredentials(String detail) 建立無效憑證錯誤static org.springframework.http.ProblemDetailbadRequest(String detail) 建立 400 Bad Requeststatic org.springframework.http.ProblemDetail建立 409 Conflictstatic org.springframework.http.ProblemDetail建立基本的 ProblemDetailstatic org.springframework.http.ProblemDetail建立帶有自訂類型的 ProblemDetailstatic org.springframework.http.ProblemDetailcredentialsExpired(String detail) 建立憑證過期錯誤static org.springframework.http.ProblemDetail建立 403 Forbiddenstatic org.springframework.http.ProblemDetailfromStatusCode(int statusCode, String detail) 從 HTTP 狀態碼建立 ProblemDetailstatic org.springframework.http.ProblemDetailinternalError(String detail) 建立 500 Internal Server Errorstatic org.springframework.http.ProblemDetail建立 404 Not Foundstatic org.springframework.http.ProblemDetailunauthorized(String detail) 建立 401 Unauthorizedstatic org.springframework.http.ProblemDetailunprocessableEntity(String detail) 建立 422 Unprocessable Entity(業務規則違反)static org.springframework.http.ProblemDetailvalidationError(String detail, Set<Violation> violations) 建立驗證錯誤的 ProblemDetailstatic org.springframework.http.ProblemDetailwithErrorCode(org.springframework.http.ProblemDetail problem, String errorCode) 設定錯誤代碼static org.springframework.http.ProblemDetail設定國際化參數
-
Method Details
-
create
public static org.springframework.http.ProblemDetail create(org.springframework.http.HttpStatus status, String detail) 建立基本的 ProblemDetail- Parameters:
status- HTTP 狀態detail- 詳細描述- Returns:
- ProblemDetail
-
create
-
badRequest
建立 400 Bad Request -
unauthorized
建立 401 Unauthorized -
accountLocked
建立帳號鎖定錯誤 -
accountDisabled
建立帳號停用錯誤 -
accountExpired
建立帳號過期錯誤 -
credentialsExpired
建立憑證過期錯誤 -
badCredentials
建立無效憑證錯誤 -
forbidden
建立 403 Forbidden -
notFound
建立 404 Not Found -
conflict
建立 409 Conflict -
unprocessableEntity
建立 422 Unprocessable Entity(業務規則違反) -
internalError
建立 500 Internal Server Error -
validationError
-
withErrorCode
public static org.springframework.http.ProblemDetail withErrorCode(org.springframework.http.ProblemDetail problem, String errorCode) 設定錯誤代碼 -
withI18n
-
fromStatusCode
從 HTTP 狀態碼建立 ProblemDetail
-