Skip to content

Commit

Permalink
UI: Remove duplication in IslandHttpClient
Browse files Browse the repository at this point in the history
  • Loading branch information
shreyamalviya authored and VakarisZ committed Sep 6, 2023
1 parent fc16082 commit 53a31ce
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions monkey/monkey_island/cc/ui/src/components/IslandHttpClient.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,7 @@ class IslandHttpClient extends AuthComponent {
}

_post(endpoint: string, contents: any, headers: Record<string, any>={}, refreshToken: boolean = false): Promise<Response> {
let status = null;
return this.authFetch(endpoint,
{
method: 'POST',
headers: headers,
body: contents
},
refreshToken
)
.then(res => {
status = res.status;
return res
})
.then(res => new Response(res, status));
return this._makeRequest('POST', endpoint, contents, headers, refreshToken)
}

put(endpoint: string, contents: any, refreshToken: boolean = false): Promise<Response> {
Expand All @@ -64,10 +51,14 @@ class IslandHttpClient extends AuthComponent {
}

_put(endpoint: string, contents: any, headers: Record<string, any>={}, refreshToken: boolean = false): Promise<Response> {
return this._makeRequest('PUT', endpoint, contents, headers, refreshToken)
}

_makeRequest(method: string, endpoint: string, contents: any, headers: Record<string, any>={}, refreshToken: boolean = false): Promise<Response> {
let status = null;
return this.authFetch(endpoint,
{
method: 'PUT',
method: method,
headers: headers,
body: contents
},
Expand Down

0 comments on commit 53a31ce

Please sign in to comment.