diff --git a/HTTPS API.md b/HTTPS API.md index e4d913a..da90300 100644 --- a/HTTPS API.md +++ b/HTTPS API.md @@ -22,6 +22,9 @@ encounters errors processing your request, this will be false and an error code will be added to the response. Otherwise, the response data (if any) will be in the `result` key. +The `X-Force-OK` header can be set to `true` to force a `200 OK` reply even +when an error occurs. + ### Examples ```json diff --git a/lurkcoin/api/https-core.go b/lurkcoin/api/https-core.go index cc66702..d2ab553 100644 --- a/lurkcoin/api/https-core.go +++ b/lurkcoin/api/https-core.go @@ -172,3 +172,12 @@ func MakeHTTPRouter(db lurkcoin.Database, config *Config) *httprouter.Router { addV2API(router, db, config.Name) return router } + +func isYes(s string) bool { + switch strings.ToLower(s) { + case "true", "yes", "y", "1": + return true + default: + return false + } +} diff --git a/lurkcoin/api/v2.go b/lurkcoin/api/v2.go index 55a6411..4b3bd7c 100644 --- a/lurkcoin/api/v2.go +++ b/lurkcoin/api/v2.go @@ -157,15 +157,6 @@ func v2Post(router *httprouter.Router, db lurkcoin.Database, url string, router.POST(url, f2) } -func v2IsYes(s string) bool { - switch strings.ToLower(s) { - case "true", "yes", "y", "1": - return true - default: - return false - } -} - func addV2API(router *httprouter.Router, db lurkcoin.Database, lurkcoinName string) { @@ -205,7 +196,7 @@ func addV2API(router *httprouter.Router, db lurkcoin.Database, } _, err = r.Server.Pay("", target, targetServer, - amount, v2IsYes(f.Get("local_currency")), true) + amount, isYes(f.Get("local_currency")), true) if err != nil { return nil, err } @@ -284,7 +275,7 @@ func addV2API(router *httprouter.Router, db lurkcoin.Database, transaction.String(), } } - if v2IsYes(f.Get("as_object")) { + if isYes(f.Get("as_object")) { _, exc := r.Server.GetExchangeRate(c1, false) return map[string]interface{}{ "exchange_rate": json.RawMessage(exc.String()), diff --git a/lurkcoin/api/v3.go b/lurkcoin/api/v3.go index db8f218..02b8c4e 100644 --- a/lurkcoin/api/v3.go +++ b/lurkcoin/api/v3.go @@ -56,7 +56,13 @@ func v3WrapHTTPHandler(db lurkcoin.Database, autoLogin bool, var c int res["success"] = false res["error"], res["message"], c = lurkcoin.LookupError(err.Error()) - w.WriteHeader(c) + + // Workaround for limitations of Minetest's HTTP API + if isYes(r.Header.Get("X-Force-OK")) { + w.WriteHeader(http.StatusOK) + } else { + w.WriteHeader(c) + } } // TODO: Possibly write JSON directly to the ResponseWriter. diff --git a/lurkcoin/misc.go b/lurkcoin/misc.go index f150371..1db78af 100644 --- a/lurkcoin/misc.go +++ b/lurkcoin/misc.go @@ -35,7 +35,7 @@ import ( ) const SYMBOL = "ยค" -const VERSION = "3.0.4" +const VERSION = "3.0.5" // Note that public source code is required by the AGPL const SOURCE_URL = "https://github.com/luk3yx/lurkcoin-core"