Skip to content

Commit

Permalink
fix: intermittent create page error (#837)
Browse files Browse the repository at this point in the history
* add restrictions to malformation check

* remove unnecessary code snippet
  • Loading branch information
thewahome committed Feb 10, 2021
1 parent 4ab6fe9 commit 9b102b5
Showing 1 changed file with 18 additions and 13 deletions.
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

0 comments on commit 9b102b5

Please sign in to comment.