Add session expiry renewal flow
This commit is contained in:
@@ -10,6 +10,7 @@ signal feedback_failed(message: String)
|
||||
var api_url := DEFAULT_API_URL
|
||||
var request: HTTPRequest
|
||||
var is_submitting := false
|
||||
var request_access_token := ""
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
@@ -25,13 +26,14 @@ func _ready() -> void:
|
||||
func submit(category: String, details: String, context: Dictionary) -> void:
|
||||
if is_submitting:
|
||||
return
|
||||
if AuthState.access_token.is_empty():
|
||||
if not AuthState.can_send_authenticated_request():
|
||||
feedback_failed.emit("Log in before sending feedback.")
|
||||
return
|
||||
is_submitting = true
|
||||
request_access_token = AuthState.access_token
|
||||
var headers := PackedStringArray([
|
||||
"Content-Type: application/json",
|
||||
"Authorization: Bearer %s" % AuthState.access_token
|
||||
"Authorization: Bearer %s" % request_access_token
|
||||
])
|
||||
var payload := {"category": category, "details": details, "context": context}
|
||||
var error := request.request(api_url, headers, HTTPClient.METHOD_POST, JSON.stringify(payload))
|
||||
@@ -58,6 +60,8 @@ func build_context(screen_name: String, viewport_size: Vector2) -> Dictionary:
|
||||
|
||||
func _on_request_completed(result: int, response_code: int, _headers: PackedStringArray, body: PackedByteArray) -> void:
|
||||
is_submitting = false
|
||||
if response_code == 401:
|
||||
AuthState.handle_unauthorized(request_access_token)
|
||||
if result != HTTPRequest.RESULT_SUCCESS or response_code < 200 or response_code >= 300:
|
||||
var detail := body.get_string_from_utf8().strip_edges().left(240)
|
||||
var message := "Feedback submission failed with status %d." % response_code
|
||||
|
||||
Reference in New Issue
Block a user