fix: properly await async functions and correct fetch usage #3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Added missing 'await' keywords, fixed typos in fetch options, correctly processed fetch responses with res.text(), and corrected form data methods to ensure proper execution. #2
代码修复说明:
正确使用
await
关键字:getToken()
时,缺少await
,导致获取不到实际返回值。await
,以等待 Promise 完成:修正拼写错误:
fetch
选项中,reponseType
拼写错误,应该为responseType
。正确处理异步操作:
res.data
可能无法正确获取内容。await res.text()
获取响应的文本内容:修正表单数据的使用:
FormData
方法,如insert
,标准方法应为append
。FormData.append()
方法。完善请求头信息:
增强错误处理和日志输出:
try-catch
块和console.log
语句,以便更好地调试和处理错误。一致使用 Async/Await:
await
,可能导致未预期的行为。await
,确保按顺序执行。处理响应格式:
res.text()
获取文本。总结: 通过上述修改,解决了异步处理不当、拼写错误、方法使用错误和响应解析错误等问题,确保代码按预期运行。
版本 v1.1.0 的測試截圖:
此 PR 的測試截圖: