Content-Type fixes in client4.ts and remote_cluster.go (#27887)
Co-authored-by: Mattermost Build <build@mattermost.com> Co-authored-by: Miguel de la Cruz <miguel@mcrx.me>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
b94a11e591
Коммит
84a0c09d56
@@ -539,7 +539,9 @@ func generateRemoteClusterInvite(c *Context, w http.ResponseWriter, r *http.Requ
|
|||||||
}
|
}
|
||||||
|
|
||||||
w.WriteHeader(http.StatusCreated)
|
w.WriteHeader(http.StatusCreated)
|
||||||
w.Write([]byte(inviteCode))
|
if err := json.NewEncoder(w).Encode(inviteCode); err != nil {
|
||||||
|
c.Logger.Warn("Error while writing response", mlog.Err(err))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getRemoteCluster(c *Context, w http.ResponseWriter, r *http.Request) {
|
func getRemoteCluster(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||||
@@ -663,5 +665,5 @@ func deleteRemoteCluster(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
auditRec.Success()
|
auditRec.Success()
|
||||||
w.WriteHeader(http.StatusNoContent)
|
ReturnStatusOK(w)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -605,7 +605,7 @@ func TestDeleteRemoteCluster(t *testing.T) {
|
|||||||
require.Zero(t, initialRC.DeleteAt)
|
require.Zero(t, initialRC.DeleteAt)
|
||||||
|
|
||||||
resp, err := th.SystemAdminClient.DeleteRemoteCluster(context.Background(), rc.RemoteId)
|
resp, err := th.SystemAdminClient.DeleteRemoteCluster(context.Background(), rc.RemoteId)
|
||||||
CheckNoContentStatus(t, resp)
|
CheckOKStatus(t, resp)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
deletedRC, appErr := th.App.GetRemoteCluster(rc.RemoteId)
|
deletedRC, appErr := th.App.GetRemoteCluster(rc.RemoteId)
|
||||||
|
|||||||
@@ -8848,11 +8848,12 @@ func (c *Client4) GenerateRemoteClusterInvite(ctx context.Context, remoteCluster
|
|||||||
}
|
}
|
||||||
defer closeBody(r)
|
defer closeBody(r)
|
||||||
|
|
||||||
b, err := io.ReadAll(r.Body)
|
var inviteCode string
|
||||||
if err != nil {
|
if err := json.NewDecoder(r.Body).Decode(&inviteCode); err != nil {
|
||||||
return "", nil, NewAppError("GenerateRemoteClusterInvite", "api.read_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
return "", nil, NewAppError("GenerateRemoteClusterInvite", "api.unmarshall_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||||
}
|
}
|
||||||
return string(b), BuildResponse(r), nil
|
|
||||||
|
return inviteCode, BuildResponse(r), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client4) GetRemoteCluster(ctx context.Context, remoteClusterId string) (*RemoteCluster, *Response, error) {
|
func (c *Client4) GetRemoteCluster(ctx context.Context, remoteClusterId string) (*RemoteCluster, *Response, error) {
|
||||||
@@ -8863,7 +8864,9 @@ func (c *Client4) GetRemoteCluster(ctx context.Context, remoteClusterId string)
|
|||||||
defer closeBody(r)
|
defer closeBody(r)
|
||||||
|
|
||||||
var rc *RemoteCluster
|
var rc *RemoteCluster
|
||||||
json.NewDecoder(r.Body).Decode(&rc)
|
if err := json.NewDecoder(r.Body).Decode(&rc); err != nil {
|
||||||
|
return nil, nil, NewAppError("GetRemoteCluster", "api.unmarshall_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||||
|
}
|
||||||
|
|
||||||
return rc, BuildResponse(r), nil
|
return rc, BuildResponse(r), nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4179,7 +4179,11 @@ export default class Client4 {
|
|||||||
|
|
||||||
let data;
|
let data;
|
||||||
try {
|
try {
|
||||||
data = await response.json();
|
if (headers.get('Content-Type') === 'application/json') {
|
||||||
|
data = await response.json();
|
||||||
|
} else {
|
||||||
|
data = await response.text();
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw new ClientError(this.getUrl(), {
|
throw new ClientError(this.getUrl(), {
|
||||||
message: 'Received invalid response from the server.',
|
message: 'Received invalid response from the server.',
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user