mirror of
https://github.com/usebruno/bruno.git
synced 2026-06-28 15:14:06 +00:00
handle oauth2 timeline response, remove dataBuffer from debugInfo obj (#4330)
This commit is contained in:
@@ -1,8 +1,26 @@
|
||||
import Headers from "../Common/Headers/index";
|
||||
import BodyBlock from "../Common/Body/index";
|
||||
|
||||
const safeStringifyJSONIfNotString = (obj) => {
|
||||
if (obj === null || obj === undefined) return '';
|
||||
|
||||
if (typeof obj === 'string') {
|
||||
return obj;
|
||||
}
|
||||
|
||||
try {
|
||||
return JSON.stringify(obj);
|
||||
} catch (e) {
|
||||
return '[Unserializable Object]';
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
const Request = ({ collection, request, item, width }) => {
|
||||
const { url, headers, data, dataBuffer, error } = request || {};
|
||||
let { url, headers, data, dataBuffer, error } = request || {};
|
||||
if (!dataBuffer) {
|
||||
dataBuffer = Buffer.from(safeStringifyJSONIfNotString(data))?.toString('base64');
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
|
||||
@@ -2,8 +2,25 @@ import BodyBlock from "../Common/Body/index";
|
||||
import Headers from "../Common/Headers/index";
|
||||
import Status from "../Common/Status/index";
|
||||
|
||||
const safeStringifyJSONIfNotString = (obj) => {
|
||||
if (obj === null || obj === undefined) return '';
|
||||
|
||||
if (typeof obj === 'string') {
|
||||
return obj;
|
||||
}
|
||||
|
||||
try {
|
||||
return JSON.stringify(obj);
|
||||
} catch (e) {
|
||||
return '[Unserializable Object]';
|
||||
}
|
||||
};
|
||||
|
||||
const Response = ({ collection, response, item, width }) => {
|
||||
const { status, statusCode, statusText, headers, data, dataBuffer, error } = response || {};
|
||||
let { status, statusCode, statusText, dataBuffer, headers, data, error } = response || {};
|
||||
if (!dataBuffer) {
|
||||
dataBuffer = Buffer.from(safeStringifyJSONIfNotString(data))?.toString('base64');
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
|
||||
@@ -1282,7 +1282,7 @@ export const fetchOauth2Credentials = (payload) => async (dispatch, getState) =>
|
||||
url,
|
||||
collectionUid,
|
||||
credentialsId,
|
||||
debugInfo,
|
||||
debugInfo: safeParseJSON(safeStringifyJSON(debugInfo)),
|
||||
folderUid: folderUid || null,
|
||||
itemUid: !folderUid ? itemUid : null
|
||||
})
|
||||
@@ -1305,7 +1305,7 @@ export const refreshOauth2Credentials = (payload) => async (dispatch, getState)
|
||||
url,
|
||||
collectionUid,
|
||||
credentialsId,
|
||||
debugInfo,
|
||||
debugInfo: safeParseJSON(safeStringifyJSON(debugInfo)),
|
||||
folderUid: folderUid || null,
|
||||
itemUid: !folderUid ? itemUid : null
|
||||
})
|
||||
|
||||
@@ -181,4 +181,4 @@ export const getEncoding = (headers) => {
|
||||
// Parse the charset from content type: https://stackoverflow.com/a/33192813
|
||||
const charsetMatch = /charset=([^()<>@,;:"/[\]?.=\s]*)/i.exec(headers?.['content-type'] || '');
|
||||
return charsetMatch?.[1];
|
||||
}
|
||||
}
|
||||
@@ -275,7 +275,6 @@ function makeAxiosInstance({
|
||||
statusText: error.response.statusText,
|
||||
headers: error.response.headers,
|
||||
data: errorResponseData?.toString?.(),
|
||||
dataBuffer: dataBuffer,
|
||||
size: Buffer.byteLength(dataBuffer),
|
||||
duration: error.response.headers.get('request-duration') ?? 0,
|
||||
timeline: error.response.timeline
|
||||
@@ -363,7 +362,6 @@ function makeAxiosInstance({
|
||||
statusText: error.response.statusText,
|
||||
headers: error.response.headers,
|
||||
data: errorResponseData?.toString?.(),
|
||||
dataBuffer: dataBuffer,
|
||||
size: Buffer.byteLength(dataBuffer),
|
||||
duration: error.response.headers.get('request-duration') ?? 0,
|
||||
timeline
|
||||
|
||||
@@ -158,7 +158,6 @@ const getOAuth2TokenUsingAuthorizationCode = async ({ request, collectionUid, fo
|
||||
url: config.url,
|
||||
headers: config.headers,
|
||||
data: requestData,
|
||||
dataBuffer: Buffer.from(requestData),
|
||||
timestamp: Date.now(),
|
||||
};
|
||||
return config;
|
||||
@@ -220,14 +219,12 @@ const getOAuth2TokenUsingAuthorizationCode = async ({ request, collectionUid, fo
|
||||
method: axiosRequestInfo?.method,
|
||||
headers: axiosRequestInfo?.headers || {},
|
||||
data: axiosRequestInfo?.data,
|
||||
dataBuffer: axiosRequestInfo?.dataBuffer,
|
||||
error: null
|
||||
},
|
||||
response: {
|
||||
url: axiosResponseInfo?.url,
|
||||
headers: axiosResponseInfo?.headers,
|
||||
data: parsedResponseData,
|
||||
dataBuffer: axiosResponseInfo?.data,
|
||||
status: axiosResponseInfo?.status,
|
||||
statusText: axiosResponseInfo?.statusText,
|
||||
error: axiosResponseInfo?.error,
|
||||
@@ -386,7 +383,6 @@ const getOAuth2TokenUsingClientCredentials = async ({ request, collectionUid, fo
|
||||
url: config.url,
|
||||
headers: config.headers,
|
||||
data: requestData,
|
||||
dataBuffer: Buffer.from(requestData),
|
||||
timestamp: Date.now(),
|
||||
};
|
||||
return config;
|
||||
@@ -442,14 +438,12 @@ const getOAuth2TokenUsingClientCredentials = async ({ request, collectionUid, fo
|
||||
method: axiosRequestInfo?.method,
|
||||
headers: axiosRequestInfo?.headers || {},
|
||||
data: axiosRequestInfo?.data,
|
||||
dataBuffer: axiosRequestInfo?.dataBuffer,
|
||||
error: null
|
||||
},
|
||||
response: {
|
||||
url: axiosResponseInfo.url,
|
||||
headers: axiosResponseInfo?.headers,
|
||||
data: parsedResponseData,
|
||||
dataBuffer: axiosResponseInfo?.data,
|
||||
status: axiosResponseInfo?.status,
|
||||
statusText: axiosResponseInfo?.statusText,
|
||||
timeline: axiosResponseInfo?.timeline,
|
||||
@@ -576,7 +570,6 @@ const getOAuth2TokenUsingPasswordCredentials = async ({ request, collectionUid,
|
||||
url: config.url,
|
||||
headers: config.headers,
|
||||
data: requestData,
|
||||
dataBuffer: Buffer.from(requestData),
|
||||
timestamp: Date.now(),
|
||||
};
|
||||
return config;
|
||||
@@ -631,14 +624,12 @@ const getOAuth2TokenUsingPasswordCredentials = async ({ request, collectionUid,
|
||||
method: axiosRequestInfo?.method,
|
||||
headers: axiosRequestInfo?.headers || {},
|
||||
data: axiosRequestInfo?.data,
|
||||
dataBuffer: axiosRequestInfo?.dataBuffer,
|
||||
error: null
|
||||
},
|
||||
response: {
|
||||
url: axiosResponseInfo?.url,
|
||||
headers: axiosResponseInfo?.headers,
|
||||
data: parsedResponseData,
|
||||
dataBuffer: axiosResponseInfo?.data,
|
||||
status: axiosResponseInfo?.status,
|
||||
statusText: axiosResponseInfo?.statusText,
|
||||
timeline: axiosResponseInfo?.timeline,
|
||||
@@ -697,7 +688,6 @@ const refreshOauth2Token = async (requestCopy, collectionUid) => {
|
||||
url: config.url,
|
||||
headers: config.headers,
|
||||
data: requestData,
|
||||
dataBuffer: Buffer.from(requestData),
|
||||
timestamp: Date.now(),
|
||||
};
|
||||
return config;
|
||||
@@ -755,14 +745,12 @@ const refreshOauth2Token = async (requestCopy, collectionUid) => {
|
||||
method: axiosRequestInfo?.method,
|
||||
headers: axiosRequestInfo?.headers || {},
|
||||
data: axiosRequestInfo?.data,
|
||||
dataBuffer: axiosRequestInfo?.dataBuffer,
|
||||
error: null
|
||||
},
|
||||
response: {
|
||||
url: axiosResponseInfo?.url,
|
||||
headers: axiosResponseInfo?.headers,
|
||||
data: parsedResponseData,
|
||||
dataBuffer: axiosResponseInfo?.data,
|
||||
status: axiosResponseInfo?.status,
|
||||
statusText: axiosResponseInfo?.statusText,
|
||||
timeline: axiosResponseInfo?.timeline,
|
||||
|
||||
Reference in New Issue
Block a user