@@ -121,8 +121,10 @@ void URequestHandler::ProcessAndThen(TFunction<void(UTexture2D*)> OnSuccess, FFa
121121 if (!Response.IsValid ())
122122 {
123123 OnFailure (FSequenceError (RequestFail, " The Request is invalid!" ));
124+ } else
125+ {
126+ OnFailure (FSequenceError (RequestFail, " Request failed: " + Response->GetContentAsString ()));
124127 }
125- OnFailure (FSequenceError (RequestFail, " Request failed: " + Response->GetContentAsString ()));
126128 }// if wasn't successful
127129 // catch all error case!
128130 OnFailure (FSequenceError (RequestFail, " Failed to build QR Image data" ));
@@ -132,32 +134,51 @@ void URequestHandler::ProcessAndThen(TFunction<void(UTexture2D*)> OnSuccess, FFa
132134void URequestHandler::ProcessAndThen (TFunction<void (FString)> OnSuccess, FFailureCallback OnFailure) const
133135{
134136 Process ().BindLambda ([OnSuccess, OnFailure](FHttpRequestPtr Req, const FHttpResponsePtr& Response, const bool bWasSuccessful)
137+ {
138+ FString CurlCommand = FString::Printf (
139+ TEXT (" curl -X %s \" %s\" -H \" Content-Type: application/json\" -H \" Accept: application/json\" -H \" X-Access-Key: %s\" --data \" %s\" " ),
140+ *Req->GetVerb (),
141+ *Req->GetURL (),
142+ *Req->GetHeader (" X-Access-Key" ),
143+ *FString::Printf (TEXT (" %s" ),*FString (UTF8_TO_TCHAR (Req->GetContent ().GetData ())).Replace (TEXT (" \" " ), TEXT (" \\\" " )))
144+ );
145+
146+ SEQ_LOG_EDITOR (Log,TEXT (" %s" ), *CurlCommand);
147+ SEQ_LOG_EDITOR (Log,TEXT (" %s" ), *Response->GetContentAsString ());
148+
149+ if (bWasSuccessful)
135150 {
136- FString CurlCommand = FString::Printf (
137- TEXT (" curl -X %s \" %s\" -H \" Content-Type: application/json\" -H \" Accept: application/json\" -H \" X-Access-Key: %s\" --data \" %s\" " ),
138- *Req->GetVerb (),
139- *Req->GetURL (),
140- *Req->GetHeader (" X-Access-Key" ),
141- *FString::Printf (TEXT (" %s" ),*FString (UTF8_TO_TCHAR (Req->GetContent ().GetData ())).Replace (TEXT (" \" " ), TEXT (" \\\" " )))
142- );
143-
144- SEQ_LOG_EDITOR (Log,TEXT (" %s" ), *CurlCommand);
145- SEQ_LOG_EDITOR (Log,TEXT (" %s" ), *Response->GetContentAsString ());
146-
147- if (bWasSuccessful)
151+ OnSuccess (Response->GetContentAsString ());
152+ }
153+ else
154+ {
155+ if (Response.IsValid ())
148156 {
149- OnSuccess ( Response->GetContentAsString ());
157+ OnFailure ( FSequenceError (RequestFail, " Request is invalid " + Response->GetContentAsString () ));
150158 }
151159 else
152160 {
153- if (Response.IsValid ())
154- {
155- OnFailure (FSequenceError (RequestFail, " Request is invalid" + Response->GetContentAsString ()));
156- }
157- else
158- {
159- OnFailure (FSequenceError (RequestFail, " Request failed: No response received!" ));
160- }
161+ OnFailure (FSequenceError (RequestFail, " Request failed: No response received!" ));
161162 }
162- });
163+ }
164+ });
165+ }
166+
167+ void URequestHandler::ProcessAndThen (TSuccessCallback<FHttpResponsePtr> OnSuccess,
168+ const FFailureCallback& OnFailure) const
169+ {
170+ Process ().BindLambda ([OnSuccess, OnFailure](FHttpRequestPtr Req, const FHttpResponsePtr& Response, const bool bWasSuccessful)
171+ {
172+ if (bWasSuccessful)
173+ {
174+ OnSuccess (Response);
175+ }
176+ else
177+ {
178+ if (!Response.IsValid ())
179+ OnFailure (FSequenceError (RequestFail, " The Request is invalid!" ));
180+ else
181+ OnFailure (FSequenceError (RequestFail, " Request failed: " + Response->GetContentAsString ()));
182+ }
183+ });
163184}
0 commit comments