mirror of
https://github.com/YMFE/yapi.git
synced 2024-12-03 04:50:32 +08:00
fix: 当接口返回 body 不是 json,高级 mock 功能报错
This commit is contained in:
parent
449e707a2e
commit
d7e6e7d761
@ -25,7 +25,7 @@ const roleAction = {
|
||||
exports.isJson = function(json){
|
||||
if(!json) return false;
|
||||
try{
|
||||
json = JSON.parse(json);
|
||||
json = json5.parse(json);
|
||||
return json;
|
||||
}catch(e){
|
||||
return false;
|
||||
@ -260,7 +260,12 @@ exports.handleJson = handleJson;
|
||||
exports.handleParamsValue = handleParamsValue;
|
||||
|
||||
exports.getMockText = (mockTpl) => {
|
||||
try{
|
||||
return JSON.stringify(Mock.mock(MockExtra(json5.parse(mockTpl), {})), null, " ")
|
||||
}catch(err){
|
||||
return ''
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -285,17 +285,15 @@ export default class Run extends Component {
|
||||
let reqBody;
|
||||
if (bodyType === 'form') {
|
||||
reqBody = this.arrToObj(bodyForm)
|
||||
} else {
|
||||
} else if(bodyType === 'json'){
|
||||
reqBody = isJson(bodyOther);
|
||||
if (reqBody === false) {
|
||||
if (bodyType === 'json' && HTTP_METHOD[method].request_body) {
|
||||
return message.error('请求 Body 的 json 格式有误')
|
||||
}
|
||||
reqBody = bodyOther;
|
||||
} else {
|
||||
reqBody = handleJson(reqBody, this.handleValue)
|
||||
}
|
||||
|
||||
}else{
|
||||
reqBody = bodyOther;
|
||||
}
|
||||
|
||||
this.setState({ loading: true })
|
||||
@ -545,11 +543,6 @@ export default class Run extends Component {
|
||||
}, 0);
|
||||
}
|
||||
|
||||
// @autobind
|
||||
// fileChange(e, index) {
|
||||
// console.log(e)
|
||||
// console.log(index)
|
||||
// }
|
||||
|
||||
@autobind
|
||||
onTestSwitched(checked) {
|
||||
|
@ -168,6 +168,7 @@ class InterfaceEditForm extends Component {
|
||||
|
||||
values.method = this.state.method;
|
||||
values.req_params = values.req_params || [];
|
||||
values.req_headers = values.req_headers || [];
|
||||
let isfile = false, isHavaContentType = false;
|
||||
if (values.req_body_type === 'form') {
|
||||
values.req_body_form.forEach((item) => {
|
||||
|
Loading…
Reference in New Issue
Block a user