فهرست منبع

client: Try to parse response Body on InternalServerError

Try to parse the response body from the server when an HTTP 500 is
returned (i.e. http.StatusInternalServerError) as it might contain
useful information. If successful, create a new error and append that
information to the returned error message. Otherwise just maintain the
same behavior
Alexandros Kosiaris 4 سال پیش
والد
کامیت
638643cda7
1فایلهای تغییر یافته به همراه9 افزوده شده و 2 حذف شده
  1. 9 2
      client/request.go

+ 9 - 2
client/request.go

@@ -104,8 +104,15 @@ func (r *request) execute(method, path string, data interface{}) (io.ReadCloser,
 		response.Body.Close()
 		return nil, ErrForbidden
 	case http.StatusInternalServerError:
-		response.Body.Close()
-		return nil, ErrServerError
+		defer response.Body.Close()
+
+		var resp errorResponse
+		decoder := json.NewDecoder(response.Body)
+		// If we failed to decode, just return a generic ErrServerError
+		if err := decoder.Decode(&resp); err != nil {
+			return nil, ErrServerError
+		}
+		return nil, errors.New("miniflux: internal server error: " + resp.ErrorMessage)
 	case http.StatusNotFound:
 		response.Body.Close()
 		return nil, ErrNotFound