forked from xiangwang25/whale-town-front-v2
refactor: harden client runtime and exports
This commit is contained in:
@@ -21,24 +21,24 @@ func _exit_tree() -> void:
|
||||
request.queue_free()
|
||||
_activeRequests.clear()
|
||||
|
||||
func get_json(endpoint: String, callback: Callable, authenticated: bool = true) -> void:
|
||||
request_json(endpoint, {}, callback, HTTPClient.METHOD_GET, authenticated)
|
||||
func get_json(endpoint: String, callback: Callable, authenticated: bool = true, timeout: float = REQUEST_TIMEOUT) -> void:
|
||||
request_json(endpoint, {}, callback, HTTPClient.METHOD_GET, authenticated, timeout)
|
||||
|
||||
func post_json(endpoint: String, payload: Dictionary, callback: Callable, authenticated: bool = true) -> void:
|
||||
request_json(endpoint, payload, callback, HTTPClient.METHOD_POST, authenticated)
|
||||
func post_json(endpoint: String, payload: Dictionary, callback: Callable, authenticated: bool = true, timeout: float = REQUEST_TIMEOUT) -> void:
|
||||
request_json(endpoint, payload, callback, HTTPClient.METHOD_POST, authenticated, timeout)
|
||||
|
||||
func patch_json(endpoint: String, payload: Dictionary, callback: Callable, authenticated: bool = true) -> void:
|
||||
request_json(endpoint, payload, callback, HTTPClient.METHOD_PATCH, authenticated)
|
||||
func patch_json(endpoint: String, payload: Dictionary, callback: Callable, authenticated: bool = true, timeout: float = REQUEST_TIMEOUT) -> void:
|
||||
request_json(endpoint, payload, callback, HTTPClient.METHOD_PATCH, authenticated, timeout)
|
||||
|
||||
func put_json(endpoint: String, payload: Dictionary, callback: Callable, authenticated: bool = true) -> void:
|
||||
request_json(endpoint, payload, callback, HTTPClient.METHOD_PUT, authenticated)
|
||||
func put_json(endpoint: String, payload: Dictionary, callback: Callable, authenticated: bool = true, timeout: float = REQUEST_TIMEOUT) -> void:
|
||||
request_json(endpoint, payload, callback, HTTPClient.METHOD_PUT, authenticated, timeout)
|
||||
|
||||
func delete_json(endpoint: String, payload: Dictionary, callback: Callable, authenticated: bool = true) -> void:
|
||||
request_json(endpoint, payload, callback, HTTPClient.METHOD_DELETE, authenticated)
|
||||
func delete_json(endpoint: String, payload: Dictionary, callback: Callable, authenticated: bool = true, timeout: float = REQUEST_TIMEOUT) -> void:
|
||||
request_json(endpoint, payload, callback, HTTPClient.METHOD_DELETE, authenticated, timeout)
|
||||
|
||||
func request_json(endpoint: String, payload: Dictionary, callback: Callable, method: int = HTTPClient.METHOD_GET, authenticated: bool = true) -> void:
|
||||
func request_json(endpoint: String, payload: Dictionary, callback: Callable, method: int = HTTPClient.METHOD_GET, authenticated: bool = true, timeout: float = REQUEST_TIMEOUT) -> void:
|
||||
var request := HTTPRequest.new()
|
||||
request.timeout = REQUEST_TIMEOUT
|
||||
request.timeout = timeout
|
||||
add_child(request)
|
||||
_activeRequests.append(request)
|
||||
|
||||
@@ -100,6 +100,9 @@ func _handle_response(endpoint: String, result: int, responseCode: int, body: Pa
|
||||
"response_code": responseCode,
|
||||
"error_code": str(response.get("error_code", ""))
|
||||
}
|
||||
for key in response.keys():
|
||||
if not errorInfo.has(key):
|
||||
errorInfo[key] = response[key]
|
||||
request_failed.emit(endpoint, str(errorInfo.get("message", "请求失败")))
|
||||
callback.call(false, response, errorInfo)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user