egret-labs / egret-target-wxgame

62 stars 82 forks source link

修复 responseType设置为"json",但是作为普通字符串处理的bug #1

Closed eos3tion closed 5 years ago

himuil commented 6 years ago

HttpResponseType常量里没有json类型吧

eos3tion commented 6 years ago

@himuil 有的 https://developer.mozilla.org/zh-CN/docs/Web/API/XMLHttpRequest/responseType

Value Data type of response property
"" DOMString (this is the default value)
"arraybuffer" ArrayBuffer
"blob" Blob
"document" Document
"json" JavaScript object, parsed from a JSON string returned by the server
"text" DOMString

另外你自己代码里面也写的有这个常量
https://github.com/egret-labs/egret-target-wxgame/blob/master/src/WebHttpRequest.ts#L61

 /**
  * @private
  */
private _responseType: "" | "arraybuffer" | "blob" | "document" | "json" | "text";
runinspring commented 5 years ago

因为返回值不一定是 json 格式,可能是服务器的报错信息。暂时按照字符串处理

eos3tion commented 5 years ago

@runinspring 你看了我的改动的代码么? 服务器报错,如果是http的标准处理应该是基于 status 判断,服务端应该给一个 500 区段的status
这块改动是针对小游戏File API,读取本地文件的
如果发生错误,是会进 fail 回调

runinspring commented 5 years ago

是这样的,我们遇到过某些开发者,他们服务器请求出错时,不管 HttpResponseType 设置成什么,都直接返回 invalidate request 之类的字符串。如果 用 JSON.parse() 就会报错了

eos3tion commented 5 years ago

@runinspring 但是这块处理的只是走本地 FileAPI 而不是 http那部分的流程,不经过远程服务器的啊

runinspring commented 5 years ago

又看了一下,你这个改动是对的,感谢反馈!