Skip to content

Commit

Permalink
fix: Issue when sharing request that isn't json
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbrazier committed Jul 27, 2020
1 parent 06e557b commit 202c31d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export default function App() {
fetch('https://httpstat.us/302');
fetch('https://httpstat.us/400');
fetch('https://httpstat.us/500');
// Non JSON response
fetch('https://postman-echo.com/stream/2');
// Test requests that fail
// fetch('https://failingrequest');
};
Expand Down
10 changes: 9 additions & 1 deletion src/components/RequestDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,17 @@ const RequestDetails: React.FC<Props> = ({ request, onClose }) => {
const requestBody = request.getRequestBody();

const getFullRequest = () => {
let response;
if (responseBody) {
try {
response = JSON.parse(responseBody);
} catch {
response = `${responseBody}`;
}
}
const processedRequest = {
...request,
response: responseBody ? JSON.parse(responseBody) : undefined,
response,
duration: request.duration,
};
return JSON.stringify(processedRequest, null, 2);
Expand Down

0 comments on commit 202c31d

Please sign in to comment.