-
Notifications
You must be signed in to change notification settings - Fork 594
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dispaly-warning-policy-apiserver-workloads-res
- Loading branch information
1 parent
5a66e79
commit 47b291a
Showing
10 changed files
with
117 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
frontend/packages/console-shared/src/utils/get-console-response-details.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { K8sResourceCommon } from '@console/internal/module/k8s'; | ||
|
||
const parseData = async (response) => { | ||
const text = await response.text(); | ||
const isPlainText = response.headers.get('Content-Type') === 'text/plain'; | ||
if (!text) { | ||
return isPlainText ? '' : {}; | ||
} | ||
return isPlainText || !response.ok ? text : JSON.parse(text); | ||
}; | ||
|
||
/** | ||
* This function takes a response object, converts the response to JSON or text, and then returns the data, headers, and status. | ||
* @param {Response} response - The response object to process. | ||
* @return {Promise<{ data: R, headers: Headers, status: number }>} - A promise that resolves to an object containing the data, headers, and status of the response. | ||
*/ | ||
export const getConsoleResponseDetails = async <R extends K8sResourceCommon>( | ||
response: Response, | ||
): Promise<{ data: R; headers: Headers; status: number }> => { | ||
const res = await response; | ||
const data = await parseData(res); | ||
const { headers, status } = res; | ||
return { data, headers, status }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters