Harmony开发【笔记1】报错解决(字段名写错了。。)
在利用axios从网络接收请求时,发现返回obj的code为“-1”,非常不解,利用console.log测试,更加不解,可知抛出错误是 “ E 其他错误: userName required”。但是我在测试时,它并没有体现为空,
if (!data.useName) {
console.error("userName 为空或未提供");
throw new Error("userName 为空或未提供");
}
为此,我在多处测试,日志如下
I 返回参数 {"useName":"18070538251","passWord":"040726"}
01-05 17:50:20.519 33064-28552 A0c0d0/JSAPP I http
01-05 17:50:20.520 33064-28552 A0c0d0/JSAPP I request {"transitional":{"silentJSONParsing":true,"forcedJSONParsing":true,"clarifyTimeoutError":false},"adapter":["ohos"],"transformRequest":[null],"transformResponse":[null],"timeout":0,"xsrfCookieName":"XSRF-TOKEN","xsrfHeaderName":"X-XSRF-TOKEN","maxContentLength":-1,"maxBodyLength":-1,"env":{"Blob":null},"headers":{"Accept":"application/json, text/plain, */*","Terminal":"h5","h-token":""},"baseURL":"http://159.75.169.224:3321/v3pz","url":"/login","method":"post","data":{"useName":"18070538251","passWord":"040726"}}
01-05 17:50:20.520 33064-28552 A02230/[axios] D : http url:http://159.75.169.224:3321/v3pz/login, options: {"method":"POST","header":{"Accept":"application/json, text/plain, */*","Content-Type":"application/json","Terminal":"h5","h-token":""},"readTimeout":0,"maxLimit":-1,"extraData":"{\"useName\":\"18070538251\",\"passWord\":\"040726\"}"}
01-05 17:50:20.613 33064-28552 A0c0d0/JSAPP I code -1
01-05 17:50:20.614 33064-28552 A0c0d0/JSAPP I 输入obj: {"code":-1,"message":"userName required","data":null}
01-05 17:50:20.614 33064-28552 A0c0d0/JSAPP E 其他错误: userName required
仍然不解,先记录,后续后思路再回来解答。
很明显我的字段名错了。。。
利用postman调试时终于又认真认真看了一遍,难绷哈。之前还在想是不是后端数据没掉了。但说真的,我的debug能力还是要增强,关于网络部分我也不是很熟悉。哎。
但还是恭喜我吧哈哈哈。
Day03陪诊。