33using Newtonsoft . Json . Linq ;
44using SER . Code . ArgumentSystem . Arguments ;
55using SER . Code . ArgumentSystem . BaseArguments ;
6+ using SER . Code . Helpers ;
67using SER . Code . Helpers . Exceptions ;
8+ using SER . Code . MethodSystem . BaseMethods ;
79using SER . Code . MethodSystem . BaseMethods . Synchronous ;
810using SER . Code . MethodSystem . MethodDescriptors ;
911using UnityEngine . Networking ;
@@ -21,23 +23,25 @@ public class HTTPPostMethod : SynchronousMethod, ICanError
2123 new TextArgument ( "address" ) ,
2224 new ReferenceArgument < JObject > ( "json data to post" )
2325 ] ;
24-
25- public string [ ] ErrorReasons =>
26+
27+ public static string [ ] HttpErrorReasons { get ; } =
2628 [
2729 nameof ( UnityWebRequest . Result . ConnectionError ) ,
2830 nameof ( UnityWebRequest . Result . DataProcessingError ) ,
2931 nameof ( UnityWebRequest . Result . ProtocolError )
3032 ] ;
31-
33+
34+ public string [ ] ErrorReasons => HttpErrorReasons ;
35+
3236 public override void Execute ( )
3337 {
3438 var address = Args . GetText ( "address" ) ;
3539 var jsonData = Args . GetReference < JObject > ( "json data to post" ) ;
3640
37- Timing . RunCoroutine ( SendPost ( address , jsonData . ToString ( ) ) ) ;
41+ Timing . RunCoroutine ( SendPost ( this , address , jsonData . ToString ( ) ) ) ;
3842 }
3943
40- private IEnumerator < float > SendPost ( string url , string jsonData )
44+ public static IEnumerator < float > SendPost ( Method caller , string url , string jsonData )
4145 {
4246 using UnityWebRequest request = new UnityWebRequest ( url , "POST" ) ;
4347 byte [ ] bodyRaw = System . Text . Encoding . UTF8 . GetBytes ( jsonData ) ;
@@ -47,10 +51,11 @@ private IEnumerator<float> SendPost(string url, string jsonData)
4751
4852 yield return Timing . WaitUntilDone ( request . SendWebRequest ( ) ) ;
4953
54+ Log . Signal ( $ "{ request . error } error") ;
5055 if ( request . result != UnityWebRequest . Result . Success )
5156 {
5257 throw new ScriptRuntimeError (
53- this ,
58+ caller ,
5459 $ "Address { url } has returned { request . result } ({ request . responseCode } ): { request . error } "
5560 ) ;
5661 }
0 commit comments