Add an option to always use HTTP 200 on the /v3 API
This commit is contained in:
parent
c7840406ca
commit
a5e8911855
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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()),
|
||||
|
|
|
@ -56,8 +56,14 @@ func v3WrapHTTPHandler(db lurkcoin.Database, autoLogin bool,
|
|||
var c int
|
||||
res["success"] = false
|
||||
res["error"], res["message"], c = lurkcoin.LookupError(err.Error())
|
||||
|
||||
// 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.
|
||||
raw, enc_err := json.Marshal(res)
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue