17
17
import io .clientcore .core .serialization .SerializationFormat ;
18
18
import io .clientcore .core .utils .CoreUtils ;
19
19
import io .clientcore .core .http .models .HttpResponseException ;
20
- import io .clientcore .core .http .models .HttpHeader ;
21
20
import java .lang .reflect .ParameterizedType ;
21
+ import io .clientcore .core .http .models .HttpHeader ;
22
22
23
23
/**
24
24
* Initializes a new instance of the SimpleXmlSerializableServiceImpl type.
@@ -67,9 +67,16 @@ public void sendApplicationXml(SimpleXmlSerializable simpleXmlSerializable) {
67
67
int responseCode = networkResponse .getStatusCode ();
68
68
boolean expectedResponse = responseCode == 200 ;
69
69
if (!expectedResponse ) {
70
- String errorMessage = networkResponse .getValue ().toString ();
71
- networkResponse .close ();
72
- throw new HttpResponseException (errorMessage , networkResponse , null );
70
+ BinaryData value = networkResponse .getValue ();
71
+ if (value == null || value .toBytes ().length == 0 ) {
72
+ networkResponse .close ();
73
+ throw CoreUtils .instantiateUnexpectedException (responseCode , networkResponse , null , null );
74
+ } else {
75
+ ParameterizedType returnType = null ;
76
+ Object decoded = CoreUtils .decodeNetworkResponse (value , jsonSerializer , returnType );
77
+ networkResponse .close ();
78
+ throw CoreUtils .instantiateUnexpectedException (responseCode , networkResponse , value , decoded );
79
+ }
73
80
}
74
81
networkResponse .close ();
75
82
}
@@ -93,9 +100,16 @@ public void sendTextXml(SimpleXmlSerializable simpleXmlSerializable) {
93
100
int responseCode = networkResponse .getStatusCode ();
94
101
boolean expectedResponse = responseCode == 200 ;
95
102
if (!expectedResponse ) {
96
- String errorMessage = networkResponse .getValue ().toString ();
97
- networkResponse .close ();
98
- throw new HttpResponseException (errorMessage , networkResponse , null );
103
+ BinaryData value = networkResponse .getValue ();
104
+ if (value == null || value .toBytes ().length == 0 ) {
105
+ networkResponse .close ();
106
+ throw CoreUtils .instantiateUnexpectedException (responseCode , networkResponse , null , null );
107
+ } else {
108
+ ParameterizedType returnType = null ;
109
+ Object decoded = CoreUtils .decodeNetworkResponse (value , jsonSerializer , returnType );
110
+ networkResponse .close ();
111
+ throw CoreUtils .instantiateUnexpectedException (responseCode , networkResponse , value , decoded );
112
+ }
99
113
}
100
114
networkResponse .close ();
101
115
}
@@ -113,9 +127,16 @@ public SimpleXmlSerializable getXml(String contentType) {
113
127
int responseCode = networkResponse .getStatusCode ();
114
128
boolean expectedResponse = responseCode == 200 ;
115
129
if (!expectedResponse ) {
116
- String errorMessage = networkResponse .getValue ().toString ();
117
- networkResponse .close ();
118
- throw new HttpResponseException (errorMessage , networkResponse , null );
130
+ BinaryData value = networkResponse .getValue ();
131
+ if (value == null || value .toBytes ().length == 0 ) {
132
+ networkResponse .close ();
133
+ throw CoreUtils .instantiateUnexpectedException (responseCode , networkResponse , null , null );
134
+ } else {
135
+ ParameterizedType returnType = CoreUtils .createParameterizedType (io .clientcore .annotation .processor .test .implementation .models .SimpleXmlSerializable .class );
136
+ Object decoded = CoreUtils .decodeNetworkResponse (value , jsonSerializer , returnType );
137
+ networkResponse .close ();
138
+ throw CoreUtils .instantiateUnexpectedException (responseCode , networkResponse , value , decoded );
139
+ }
119
140
}
120
141
SimpleXmlSerializable deserializedResult ;
121
142
ParameterizedType returnType = CoreUtils .createParameterizedType (SimpleXmlSerializable .class );
@@ -143,9 +164,16 @@ public SimpleXmlSerializable getInvalidXml(String contentType) {
143
164
int responseCode = networkResponse .getStatusCode ();
144
165
boolean expectedResponse = responseCode == 200 ;
145
166
if (!expectedResponse ) {
146
- String errorMessage = networkResponse .getValue ().toString ();
147
- networkResponse .close ();
148
- throw new HttpResponseException (errorMessage , networkResponse , null );
167
+ BinaryData value = networkResponse .getValue ();
168
+ if (value == null || value .toBytes ().length == 0 ) {
169
+ networkResponse .close ();
170
+ throw CoreUtils .instantiateUnexpectedException (responseCode , networkResponse , null , null );
171
+ } else {
172
+ ParameterizedType returnType = CoreUtils .createParameterizedType (io .clientcore .annotation .processor .test .implementation .models .SimpleXmlSerializable .class );
173
+ Object decoded = CoreUtils .decodeNetworkResponse (value , jsonSerializer , returnType );
174
+ networkResponse .close ();
175
+ throw CoreUtils .instantiateUnexpectedException (responseCode , networkResponse , value , decoded );
176
+ }
149
177
}
150
178
SimpleXmlSerializable deserializedResult ;
151
179
ParameterizedType returnType = CoreUtils .createParameterizedType (SimpleXmlSerializable .class );
0 commit comments