Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: intermittent create page error #837

Merged
merged 3 commits into from
Feb 10, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 18 additions & 13 deletions src/app/views/query-runner/QueryRunner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { connect } from 'react-redux';
import { bindActionCreators, Dispatch } from 'redux';

import { componentNames, eventTypes, telemetry } from '../../../telemetry';
import { ContentType } from '../../../types/enums';
import {
IQueryRunnerProps,
IQueryRunnerState,
Expand All @@ -15,6 +16,7 @@ import * as queryInputActionCreators from '../../services/actions/query-input-ac
import * as queryStatusActionCreators from '../../services/actions/query-status-action-creator';
import { sanitizeQueryUrl } from '../../utils/query-url-sanitization';
import { parseSampleUrl } from '../../utils/sample-url-generation';
import { translateMessage } from '../../utils/translate-messages';
import { QueryInput } from './query-input';
import './query-runner.scss';
import Request from './request/Request';
Expand Down Expand Up @@ -68,21 +70,24 @@ export class QueryRunner extends Component<
private handleOnRunQuery = () => {
const { sampleBody } = this.state;
const { actions, sampleQuery } = this.props;
const {
intl: { messages },
}: any = this.props;

if (sampleBody) {
try {
sampleQuery.sampleBody = JSON.parse(sampleBody);
} catch (error) {
actions!.setQueryResponseStatus({
ok: false,
statusText: messages['Malformed JSON body'],
status: `${messages['Review the request body']} ${error}`,
messageType: MessageBarType.error,
});
return;
const headers = sampleQuery.sampleHeaders;
const contentType = headers.find(k => k.name.toLowerCase() === 'content-type');
if (!contentType || (contentType.value === ContentType.Json)) {
try {
sampleQuery.sampleBody = JSON.parse(sampleBody);
} catch (error) {
actions!.setQueryResponseStatus({
ok: false,
statusText: translateMessage('Malformed JSON body'),
status: `${translateMessage('Review the request body')} ${error}`,
messageType: MessageBarType.error,
});
return;
}
} else {
sampleQuery.sampleBody = sampleBody;
}
}

Expand Down