aboutsummaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorGusted <williamzijl7@hotmail.com>2021-12-28 13:28:27 +0000
committerGitHub <noreply@github.com>2021-12-28 21:28:27 +0800
commite4e3df6c66dbeac6ac5bceff8ac4f05dbea30d70 (patch)
treeea7ef42f8d34580b8ec1319f6bc2cd84c6fb973a /modules
parentd2fac636d16a596a36a3088ff05ffe812ba6eff2 (diff)
downloadgitea-e4e3df6c66dbeac6ac5bceff8ac4f05dbea30d70.tar.gz
gitea-e4e3df6c66dbeac6ac5bceff8ac4f05dbea30d70.zip
Handle invalid issues (#18111)
* Handle invalid issues - When you hover over a issue reference, and the issue doesn't exist, it will just hang on the loading animation. - This patch fixes that by showing them the pop-up with a "Error occured" message. * Add I18N * refactor * fix comment for lint * fix unit test for i18n * fix unit test for i18n * add comments Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Diffstat (limited to 'modules')
-rw-r--r--modules/context/api.go23
1 files changed, 14 insertions, 9 deletions
diff --git a/modules/context/api.go b/modules/context/api.go
index 574d7c4248..635a54c7ef 100644
--- a/modules/context/api.go
+++ b/modules/context/api.go
@@ -30,6 +30,11 @@ type APIContext struct {
Org *APIOrganization
}
+// Currently, we have the following common fields in error response:
+// * message: the message for end users (it shouldn't be used for error type detection)
+// if we need to indicate some errors, we should introduce some new fields like ErrorCode or ErrorType
+// * url: the swagger document URL
+
// APIError is error format response
// swagger:response error
type APIError struct {
@@ -47,8 +52,8 @@ type APIValidationError struct {
// APIInvalidTopicsError is error format response to invalid topics
// swagger:response invalidTopicsError
type APIInvalidTopicsError struct {
- Topics []string `json:"invalidTopics"`
- Message string `json:"message"`
+ Message string `json:"message"`
+ InvalidTopics []string `json:"invalidTopics"`
}
//APIEmpty is an empty response
@@ -122,9 +127,9 @@ func (ctx *APIContext) InternalServerError(err error) {
})
}
-var (
- apiContextKey interface{} = "default_api_context"
-)
+type apiContextKeyType struct{}
+
+var apiContextKey = apiContextKeyType{}
// WithAPIContext set up api context in request
func WithAPIContext(req *http.Request, ctx *APIContext) *http.Request {
@@ -351,7 +356,7 @@ func ReferencesGitRepo(allowEmpty bool) func(http.Handler) http.Handler {
// NotFound handles 404s for APIContext
// String will replace message, errors will be added to a slice
func (ctx *APIContext) NotFound(objs ...interface{}) {
- var message = "Not Found"
+ var message = ctx.Tr("error.not_found")
var errors []string
for _, obj := range objs {
// Ignore nil
@@ -367,9 +372,9 @@ func (ctx *APIContext) NotFound(objs ...interface{}) {
}
ctx.JSON(http.StatusNotFound, map[string]interface{}{
- "message": message,
- "documentation_url": setting.API.SwaggerURL,
- "errors": errors,
+ "message": message,
+ "url": setting.API.SwaggerURL,
+ "errors": errors,
})
}