@@ -164,24 +164,26 @@ public function post()
164164 $ res = $ guzzle ->request ('POST ' , $ url , ['json ' => $ reqBody ]);
165165
166166 $ resCode = $ res ->getStatusCode () ?? 0 ;
167- if ($ resCode !== 200 ) {
167+ if ($ resCode !== 200 && $ resCode !== 204 ) {
168168 GA4Exception::push ("Request received code {$ resCode }" );
169169 }
170170
171- $ resBody = $ res ->getBody ()->getContents ();
172- $ data = @json_decode ($ resBody , true );
173-
174- if (empty ($ resBody )) {
175- GA4Exception::push ("Received not body " );
176- } elseif (json_last_error () != JSON_ERROR_NONE || $ data === null ) {
177- GA4Exception::push ("Could not parse response " );
178- } elseif (!empty ($ data ['validationMessages ' ])) {
179- foreach ($ data ['validationMessages ' ] as $ msg ) {
180- GA4Exception::push (
181- 'Validation Message: ' . $ msg ['validationCode ' ]
182- . (isset ($ msg ['fieldPath ' ]) ? '[ ' . $ msg ['fieldPath ' ] . ']: ' : ': ' )
183- . $ msg ['description ' ]
184- );
171+ if ($ resCode !== 204 ) {
172+ $ resBody = $ res ->getBody ()->getContents ();
173+ $ data = @json_decode ($ resBody , true );
174+
175+ if (empty ($ resBody )) {
176+ GA4Exception::push ("Received not body " );
177+ } elseif (json_last_error () != JSON_ERROR_NONE || $ data === null ) {
178+ GA4Exception::push ("Could not parse response " );
179+ } elseif (!empty ($ data ['validationMessages ' ])) {
180+ foreach ($ data ['validationMessages ' ] as $ msg ) {
181+ GA4Exception::push (
182+ 'Validation Message: ' . $ msg ['validationCode ' ]
183+ . (isset ($ msg ['fieldPath ' ]) ? '[ ' . $ msg ['fieldPath ' ] . ']: ' : ': ' )
184+ . $ msg ['description ' ]
185+ );
186+ }
185187 }
186188 }
187189 }
0 commit comments