Address code review feedback: fix Promise.race, improve statusText, use English error messages

Co-authored-by: qaiu <29825328+qaiu@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2025-12-06 22:52:37 +00:00
parent e346812c0a
commit 12a5a17a30
2 changed files with 32 additions and 2 deletions

View File

@@ -82,7 +82,7 @@ public class JsFetchBridge {
response = httpClient.getNoRedirect(url);
break;
default:
throw new IllegalArgumentException("不支持的HTTP方法: " + method);
throw new IllegalArgumentException("Unsupported HTTP method: " + method);
}
log.debug("Fetch请求完成: {} {} - 状态码: {}", method, url, response.statusCode());

View File

@@ -155,12 +155,18 @@ SimplePromise.all = function(promises) {
SimplePromise.race = function(promises) {
return new SimplePromise(function(resolve, reject) {
if (promises.length === 0) {
// Per spec, Promise.race with empty array stays pending forever
return;
}
for (var i = 0; i < promises.length; i++) {
var promise = promises[i];
if (promise && typeof promise.then === 'function') {
promise.then(resolve, reject);
} else {
resolve(promise);
return;
}
}
});
@@ -178,7 +184,31 @@ function FetchResponse(jsHttpResponse) {
this._jsResponse = jsHttpResponse;
this.status = jsHttpResponse.statusCode();
this.ok = this.status >= 200 && this.status < 300;
this.statusText = this.ok ? 'OK' : 'Error';
// Map HTTP status codes to standard status text
var statusTexts = {
200: 'OK',
201: 'Created',
204: 'No Content',
301: 'Moved Permanently',
302: 'Found',
304: 'Not Modified',
400: 'Bad Request',
401: 'Unauthorized',
403: 'Forbidden',
404: 'Not Found',
405: 'Method Not Allowed',
408: 'Request Timeout',
409: 'Conflict',
410: 'Gone',
500: 'Internal Server Error',
501: 'Not Implemented',
502: 'Bad Gateway',
503: 'Service Unavailable',
504: 'Gateway Timeout'
};
this.statusText = statusTexts[this.status] || (this.ok ? 'OK' : 'Error');
this.headers = {
get: function(name) {
return jsHttpResponse.header(name);