mirror of
https://github.com/FrankerFaceZ/FrankerFaceZ.git
synced 2025-08-05 22:00:54 +00:00
Forward application/json errors to client
This commit is contained in:
parent
d09e4e592c
commit
3ad095acf4
1 changed files with 14 additions and 3 deletions
|
@ -105,6 +105,12 @@ func HBackendPublishRequest(w http.ResponseWriter, r *http.Request) {
|
||||||
fmt.Fprint(w, count)
|
fmt.Fprint(w, count)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type BackendForwardedError string
|
||||||
|
|
||||||
|
func (bfe BackendForwardedError) Error() string {
|
||||||
|
return string(bfe)
|
||||||
|
}
|
||||||
|
|
||||||
func RequestRemoteDataCached(remoteCommand, data string, auth AuthInfo) (string, error) {
|
func RequestRemoteDataCached(remoteCommand, data string, auth AuthInfo) (string, error) {
|
||||||
cached, ok := responseCache.Get(getCacheKey(remoteCommand, data))
|
cached, ok := responseCache.Get(getCacheKey(remoteCommand, data))
|
||||||
if ok {
|
if ok {
|
||||||
|
@ -137,9 +143,6 @@ func RequestRemoteData(remoteCommand, data string, auth AuthInfo) (responseStr s
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
if resp.StatusCode != 200 {
|
|
||||||
return "", httpError(resp.StatusCode)
|
|
||||||
}
|
|
||||||
|
|
||||||
respBytes, err := ioutil.ReadAll(resp.Body)
|
respBytes, err := ioutil.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -148,6 +151,14 @@ func RequestRemoteData(remoteCommand, data string, auth AuthInfo) (responseStr s
|
||||||
|
|
||||||
responseStr = string(respBytes)
|
responseStr = string(respBytes)
|
||||||
|
|
||||||
|
if resp.StatusCode != 200 {
|
||||||
|
if resp.Header.Get("Content-Type") == "application/json" {
|
||||||
|
return "", BackendForwardedError(responseStr)
|
||||||
|
} else {
|
||||||
|
return "", httpError(resp.StatusCode)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if resp.Header.Get("FFZ-Cache") != "" {
|
if resp.Header.Get("FFZ-Cache") != "" {
|
||||||
durSecs, err := strconv.ParseInt(resp.Header.Get("FFZ-Cache"), 10, 64)
|
durSecs, err := strconv.ParseInt(resp.Header.Get("FFZ-Cache"), 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue