Godot Version
4.1.1
Question
I am making http-requests to a server using the HTTPRequest. It works good but the problem is in error handling.
For example, I submit a form it has some missing parameters. Server sents a message through error.
Lets say, required fields are {name, password}
User Submitted only name
So server sents a response code, also error messages. But that error message never I could find from Godot.
func _http_request_completed(result, response_code, _headers, body):
print(data) ## this returns html text
var json = JSON.parse_string(data)
print("json format error", json)
var ToastScene = preload("res://shared/toast/Toast.tscn").instantiate()
get_tree().root.add_child(ToastScene)
ToastScene.toast_type = ToastScene.TOAST_TYPE.FAILED
ToastScene.show_message("Request Error Occured")
## TODO: SHOW ERROR ON UI
print("request error with response code: ", response_code)
return
var json = JSON.parse_string(data)
if json:
request_completed_with_data.emit(json)
else:
request_completed_with_data.emit(data)
The backend written using laravel
How do I get that error message that server sent? If I use browser to call api in network tab I can see the error response but in godot I can’t.