summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorJohn Olheiser <42128690+jolheiser@users.noreply.github.com>2019-06-12 16:07:24 -0500
committertechknowlogick <hello@techknowlogick.com>2019-06-12 17:07:24 -0400
commit8f0182c3229dfbb8d731557e5006e39bd616b4e9 (patch)
tree3c8b8319980a19cb811acb2ffc5471b3ac71ff79 /modules
parent744fd6a1c87f2ad39dbe282133fae1190df6e538 (diff)
downloadgitea-8f0182c3229dfbb8d731557e5006e39bd616b4e9.tar.gz
gitea-8f0182c3229dfbb8d731557e5006e39bd616b4e9.zip
API error cleanup (#7186)
Diffstat (limited to 'modules')
-rw-r--r--modules/base/base.go3
-rw-r--r--modules/context/api.go13
-rw-r--r--modules/setting/setting.go12
3 files changed, 11 insertions, 17 deletions
diff --git a/modules/base/base.go b/modules/base/base.go
index 0ba72c328e..026f68f646 100644
--- a/modules/base/base.go
+++ b/modules/base/base.go
@@ -4,9 +4,6 @@
package base
-// DocURL api doc url
-const DocURL = "https://godoc.org/github.com/go-gitea/go-sdk/gitea"
-
type (
// TplName template relative path type
TplName string
diff --git a/modules/context/api.go b/modules/context/api.go
index 61f6514759..9be3fb512c 100644
--- a/modules/context/api.go
+++ b/modules/context/api.go
@@ -7,14 +7,11 @@ package context
import (
"fmt"
- "net/url"
- "path"
"strings"
"github.com/go-macaron/csrf"
"code.gitea.io/gitea/models"
- "code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
@@ -76,7 +73,7 @@ func (ctx *APIContext) Error(status int, title string, obj interface{}) {
ctx.JSON(status, APIError{
Message: message,
- URL: base.DocURL,
+ URL: setting.API.SwaggerURL,
})
}
@@ -180,15 +177,9 @@ func (ctx *APIContext) NotFound(objs ...interface{}) {
}
}
- u, err := url.Parse(setting.AppURL)
- if err != nil {
- ctx.Error(500, "Invalid AppURL", err)
- return
- }
- u.Path = path.Join(u.Path, "api", "swagger")
ctx.JSON(404, map[string]interface{}{
"message": message,
- "documentation_url": u.String(),
+ "documentation_url": setting.API.SwaggerURL,
"errors": errors,
})
}
diff --git a/modules/setting/setting.go b/modules/setting/setting.go
index b550836bc1..5471a0b61d 100644
--- a/modules/setting/setting.go
+++ b/modules/setting/setting.go
@@ -297,12 +297,14 @@ var (
// API settings
API = struct {
EnableSwagger bool
+ SwaggerURL string
MaxResponseItems int
DefaultPagingNum int
DefaultGitTreesPerPage int
DefaultMaxBlobSize int64
}{
EnableSwagger: true,
+ SwaggerURL: "",
MaxResponseItems: 50,
DefaultPagingNum: 30,
DefaultGitTreesPerPage: 1000,
@@ -581,17 +583,17 @@ func NewContext() {
AppURL = strings.TrimRight(AppURL, "/") + "/"
// Check if has app suburl.
- url, err := url.Parse(AppURL)
+ appURL, err := url.Parse(AppURL)
if err != nil {
log.Fatal("Invalid ROOT_URL '%s': %s", AppURL, err)
}
// Suburl should start with '/' and end without '/', such as '/{subpath}'.
// This value is empty if site does not have sub-url.
- AppSubURL = strings.TrimSuffix(url.Path, "/")
+ AppSubURL = strings.TrimSuffix(appURL.Path, "/")
AppSubURLDepth = strings.Count(AppSubURL, "/")
// Check if Domain differs from AppURL domain than update it to AppURL's domain
// TODO: Can be replaced with url.Hostname() when minimal GoLang version is 1.8
- urlHostname := strings.SplitN(url.Host, ":", 2)[0]
+ urlHostname := strings.SplitN(appURL.Host, ":", 2)[0]
if urlHostname != Domain && net.ParseIP(urlHostname) == nil {
Domain = urlHostname
}
@@ -900,6 +902,10 @@ func NewContext() {
log.Fatal("Failed to map Metrics settings: %v", err)
}
+ u := *appURL
+ u.Path = path.Join(u.Path, "api", "swagger")
+ API.SwaggerURL = u.String()
+
newCron()
newGit()