2017-03-28 22:45:23 +00:00
|
|
|
import React, {PureComponent} from 'react';
|
|
|
|
import autobind from 'autobind-decorator';
|
|
|
|
import jq from 'jsonpath';
|
|
|
|
import RequestSettingsModal from '../modals/request-settings-modal';
|
|
|
|
import Modal from '../base/modal';
|
|
|
|
import ModalBody from '../base/modal-body';
|
|
|
|
import ModalHeader from '../base/modal-header';
|
|
|
|
import {showModal} from './index';
|
|
|
|
import Link from '../base/link';
|
|
|
|
|
|
|
|
@autobind
|
|
|
|
class RequestRenderErrorModal extends PureComponent {
|
|
|
|
constructor (props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
|
|
|
error: null
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
_setModalRef (n) {
|
|
|
|
this.modal = n;
|
|
|
|
}
|
|
|
|
|
|
|
|
_handleShowRequestSettings () {
|
|
|
|
this.hide();
|
2017-06-16 20:29:22 +00:00
|
|
|
showModal(RequestSettingsModal, {request: this.state.request});
|
2017-03-28 22:45:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
show ({request, error}) {
|
|
|
|
this.modal.show();
|
|
|
|
this.setState({request, error});
|
|
|
|
}
|
|
|
|
|
|
|
|
hide () {
|
|
|
|
this.modal.hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
renderModalBody (request, error) {
|
|
|
|
const fullPath = `Request.${error.path}`;
|
|
|
|
|
|
|
|
const result = jq.query(request, `$.${error.path}`);
|
|
|
|
const template = (result && result.length) ? result[0] : null;
|
2017-05-15 20:55:05 +00:00
|
|
|
const locationLabel = template && template.includes('\n')
|
2017-03-28 22:45:23 +00:00
|
|
|
? `line ${error.location.line} of`
|
|
|
|
: null;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="pad">
|
|
|
|
<div className="notice warning">
|
|
|
|
<p>
|
|
|
|
Failed to render <strong>{fullPath}</strong> prior to sending
|
|
|
|
</p>
|
|
|
|
<div className="pad-top-sm">
|
2017-05-17 19:02:09 +00:00
|
|
|
{error.path.match(/^body/) && (
|
2017-03-28 22:45:23 +00:00
|
|
|
<button className="btn btn--clicky margin-right-sm"
|
|
|
|
onClick={this._handleShowRequestSettings}>
|
|
|
|
Adjust Render Settings
|
|
|
|
</button>
|
2017-05-17 19:02:09 +00:00
|
|
|
)}
|
2017-03-28 22:45:23 +00:00
|
|
|
<Link button
|
|
|
|
href="https://insomnia.rest/documentation/templating/"
|
|
|
|
className="btn btn--clicky">
|
|
|
|
Templating Documentation <i className="fa fa-external-link"/>
|
|
|
|
</Link>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<p>
|
|
|
|
<strong>Render error</strong>
|
|
|
|
<code className="block selectable">{error.message}</code>
|
|
|
|
</p>
|
|
|
|
|
|
|
|
<p>
|
|
|
|
<strong>Caused by the following field</strong>
|
|
|
|
<code className="block">
|
|
|
|
{locationLabel} {fullPath}
|
|
|
|
</code>
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
|
|
|
const {request, error} = this.state;
|
|
|
|
return (
|
|
|
|
<Modal ref={this._setModalRef} freshState>
|
|
|
|
<ModalHeader>Failed to Render Request</ModalHeader>
|
|
|
|
<ModalBody>
|
|
|
|
{(request && error) ? this.renderModalBody(request, error) : null}
|
|
|
|
</ModalBody>
|
|
|
|
</Modal>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
RequestRenderErrorModal.propTypes = {};
|
|
|
|
|
|
|
|
export default RequestRenderErrorModal;
|