File tree 4 files changed +25
-9
lines changed
4 files changed +25
-9
lines changed Original file line number Diff line number Diff line change @@ -26,9 +26,9 @@ public function auth(AuthRequest $request): AuthResponse
26
26
);
27
27
28
28
$ response = $ this ->send ($ req );
29
-
29
+ $ data = $ this -> prepareResponse ( $ response );
30
30
/** @var AuthResponse $body */
31
- $ body = $ this ->serializer ->deserialize ($ response -> getBody ()-> getContents () , AuthResponse::class, 'json ' );
31
+ $ body = $ this ->serializer ->deserialize ($ data , AuthResponse::class, 'json ' );
32
32
$ body ->statusCode = $ response ->getStatusCode ();
33
33
34
34
return $ body ;
@@ -47,9 +47,9 @@ public function logOut(LogOutRequest $request): LogOutResponse
47
47
);
48
48
49
49
$ response = $ this ->send ($ req );
50
-
50
+ $ data = $ this -> prepareResponse ( $ response );
51
51
/** @var LogOutResponse $body */
52
- $ body = $ this ->serializer ->deserialize ($ response -> getBody ()-> getContents () , LogOutResponse::class, 'json ' );
52
+ $ body = $ this ->serializer ->deserialize ($ data , LogOutResponse::class, 'json ' );
53
53
$ body ->statusCode = $ response ->getStatusCode ();
54
54
55
55
return $ body ;
Original file line number Diff line number Diff line change @@ -51,4 +51,21 @@ protected function send(RequestInterface $request): ResponseInterface
51
51
52
52
return $ response ;
53
53
}
54
+
55
+ protected function prepareResponse (ResponseInterface $ response ): string
56
+ {
57
+ if ($ response ->getStatusCode () > 300 ) {
58
+ $ array = json_decode ($ response ->getBody ()->getContents (), true );
59
+
60
+ if (isset ($ array ['error ' ]) && is_string ($ array ['error ' ])) {
61
+ $ error = $ array ['error ' ];
62
+ $ array ['error ' ] = ['message ' => $ error ];
63
+ }
64
+ $ data = json_encode ($ array , JSON_UNESCAPED_UNICODE );
65
+ } else {
66
+ $ data = $ response ->getBody ()->getContents ();
67
+ }
68
+
69
+ return $ data ;
70
+ }
54
71
}
Original file line number Diff line number Diff line change @@ -24,7 +24,7 @@ public function getInfo(GetInfoRequest $request): GetInfoResponse
24
24
);
25
25
26
26
$ response = $ this ->send ($ req );
27
- $ data = $ response -> getBody ()-> getContents ( );
27
+ $ data = $ this -> prepareResponse ( $ response );
28
28
29
29
if ($ response ->getStatusCode () >= 200 && $ response ->getStatusCode () < 300 && $ request ->params ->memberParam ->extendedFields ) {
30
30
$ array = json_decode ($ data , true );
Original file line number Diff line number Diff line change @@ -28,8 +28,7 @@ public function sendDocument(SendDocumentRequest $request): SendDocumentResponse
28
28
);
29
29
30
30
$ response = $ this ->send ($ req );
31
- $ data = $ response ->getBody ()->getContents ();
32
-
31
+ $ data = $ this ->prepareResponse ($ response );
33
32
/** @var SendDocumentResponse $body */
34
33
$ body = $ this ->serializer ->deserialize ($ data , SendDocumentResponse::class, 'json ' );
35
34
$ body ->statusCode = $ response ->getStatusCode ();
@@ -50,7 +49,7 @@ public function makeAction(MakeActionRequest $request): MakeActionResponse
50
49
);
51
50
52
51
$ response = $ this ->send ($ req );
53
- $ data = $ response -> getBody ()-> getContents ( );
52
+ $ data = $ this -> prepareResponse ( $ response );
54
53
55
54
/** @var MakeActionResponse $body */
56
55
$ body = $ this ->serializer ->deserialize ($ data , MakeActionResponse::class, 'json ' );
@@ -72,7 +71,7 @@ public function listOfChanges(ListOfChangesRequest $listOfChangesRequest): ListO
72
71
);
73
72
74
73
$ response = $ this ->send ($ req );
75
- $ data = $ response -> getBody ()-> getContents ( );
74
+ $ data = $ this -> prepareResponse ( $ response );
76
75
77
76
/** @var ListOfChangesResponse $body */
78
77
$ body = $ this ->serializer ->deserialize ($ data , ListOfChangesResponse::class, 'json ' );
You can’t perform that action at this time.
0 commit comments