|
11 | 11 | import vmRequestEditor from './request-editor/request-editor.vue'
|
12 | 12 | import vmResponseViewer from './response-viewer/response-viewer.vue'
|
13 | 13 |
|
14 |
| - import {scheduleRequest, setRequestInfo, setResponse} from '../../vuex/actions.js' |
| 14 | + import { |
| 15 | + scheduleRequest, |
| 16 | + setRequestInfo, |
| 17 | + setResponse |
| 18 | + } from '../../vuex/actions.js' |
15 | 19 | import RandExp from 'randexp'
|
16 | 20 | import requestEditorData from './request-editor/request-editor-data.js'
|
17 | 21 |
|
|
51 | 55 | // Modifies path if wheres are declared in request.
|
52 | 56 | // Otherwise, we'll send to unmodified path.
|
53 | 57 |
|
54 |
| - console.log(request.wheres) |
55 | 58 | let path = request.url
|
56 |
| - if(request.wheres){ |
| 59 | + if (request.wheres) { |
57 | 60 | let wheres = request.wheres
|
58 | 61 | for (let index in wheres) {
|
59 | 62 | let mocker = new RandExp(new RegExp(wheres[index]))
|
|
64 | 67 | }
|
65 | 68 |
|
66 | 69 | // Do sending.
|
67 |
| - this.$api.ajax(request.method, path, request.data, request.headers).then((response) => { |
68 |
| - this.setRequestInfo(response.data) |
69 |
| - this.setInfoError(false) |
70 |
| - }).catch((xhr) => { |
71 |
| - this.setInfoError(xhr.status) |
72 |
| - }) |
| 70 | + this.$api.ajax(request.method, path, request.data, request.headers) |
| 71 | + .then((response) => { |
| 72 | + this.setRequestInfo(response.data) |
| 73 | + this.setInfoError(false) |
| 74 | + }) |
| 75 | + .catch(xhr => this.setInfoError(xhr.status)) |
73 | 76 | },
|
74 | 77 | send (request){
|
75 | 78 | request = this.prepareRequest(request)
|
|
91 | 94 | getResult(request, redirects){
|
92 | 95 | this.$api.ajax(request.method, request.url, request.data, request.headers)
|
93 | 96 | .always(function (dataOrXHR, status, XHROrError) {
|
| 97 | +
|
| 98 | + let isXHR = dataOrXHR && dataOrXHR.hasOwnProperty('responseText') |
| 99 | +
|
94 | 100 | // NOTE Jquery ajax is sometimes not quite sane.
|
95 |
| - let xhr = dataOrXHR.hasOwnProperty('responseText') ? dataOrXHR : XHROrError |
| 101 | + let xhr = isXHR ? dataOrXHR : XHROrError |
96 | 102 | let data = xhr.responseText
|
97 | 103 | try {
|
98 | 104 | data = JSON.parse(data)
|
|
153 | 159 | },
|
154 | 160 | // We work with scheduled requests as with stack.
|
155 | 161 | scheduledRequests (requests){
|
156 |
| - if (requests.length === 0){ |
| 162 | + if (requests.length === 0) { |
157 | 163 | return
|
158 | 164 | }
|
159 | 165 |
|
|
0 commit comments