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: validate json #577

Merged
merged 3 commits into from
Jun 8, 2020
Merged
Show file tree
Hide file tree
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
25 changes: 20 additions & 5 deletions src/app/views/query-runner/QueryRunner.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { IDropdownOption } from 'office-ui-fabric-react';
import { IDropdownOption, MessageBarType } from 'office-ui-fabric-react';
import React, { Component } from 'react';
import { injectIntl } from 'react-intl';
import { connect } from 'react-redux';
import { bindActionCreators, Dispatch } from 'redux';

Expand All @@ -9,6 +10,7 @@ import {
} from '../../../types/query-runner';
import * as queryActionCreators from '../../services/actions/query-action-creators';
import * as queryInputActionCreators from '../../services/actions/query-input-action-creators';
import * as queryStatusActionCreators from '../../services/actions/query-status-action-creator';
import { parseSampleUrl } from '../../utils/sample-url-generation';
import './query-runner.scss';
import QueryInput from './QueryInput';
Expand Down Expand Up @@ -66,10 +68,21 @@ export class QueryRunner extends Component<

private handleOnRunQuery = () => {
const { sampleBody } = this.state;
const { actions, sampleQuery } = this.props;
const { actions, sampleQuery, } = this.props;
const { intl: { messages } }: any = this.props;

if (sampleBody) {
sampleQuery.sampleBody = JSON.parse(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;
}
}

if (actions) {
Expand Down Expand Up @@ -136,7 +149,7 @@ export class QueryRunner extends Component<
function mapDispatchToProps(dispatch: Dispatch): object {
return {
actions: bindActionCreators(
{ ...queryActionCreators, ...queryInputActionCreators },
{ ...queryActionCreators, ...queryInputActionCreators, ...queryStatusActionCreators },
dispatch
)
};
Expand All @@ -148,7 +161,9 @@ function mapStateToProps(state: any) {
};
}

// @ts-ignore
const IntlQueryRunner = injectIntl(QueryRunner);
export default connect(
mapStateToProps,
mapDispatchToProps
)(QueryRunner);
)(IntlQueryRunner);
8 changes: 5 additions & 3 deletions src/messages/GE.json
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,9 @@
"Consent": "Consent",
"permissions required to run the query": "The following permissions are required to run the query. To consent to the permissions, click Consent.",
"tab": " tab",
"View the":" View the",
"View the": " View the",
"viewing a cached set": "You are viewing a cached set of samples because of a network connection failure.",
"see more queries":"See more queries in the",
"see more queries": "See more queries in the",
"Microsoft Graph API Reference docs": "Microsoft Graph API Reference docs.",
"Fetching permissions": "Fetching permissions",
"Authentication failed": "Authentication failed",
Expand All @@ -304,5 +304,7 @@
"permissions not found": "We did not find permissions",
"selected": "selected",
"Search sample queries": "Search sample queries",
"Search history items": "Search history items"
"Search history items": "Search history items",
"Malformed JSON body": "Malformed JSON body",
"Review the request body": "Review the request body and fix any malformed JSON."
}
1 change: 1 addition & 0 deletions src/types/query-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export interface IQueryRunnerProps {
runQuery: Function;
addRequestHeader: Function;
setSampleQuery: Function;
setQueryResponseStatus: Function;
};
}

Expand Down