in AdlsDotNetSDK/WebTransport.cs [490:546]
private static void ParseRemoteError(byte[] errorBytes, int errorBytesLength, OperationResponse resp, string contentType)
{
try
{
using (MemoryStream errorStream = new MemoryStream(errorBytes, 0, errorBytesLength))
{
using (StreamReader stReader = new StreamReader(errorStream))
{
using (var jsonReader = new JsonTextReader(stReader))
{
jsonReader.Read(); //StartObject {
jsonReader.Read(); //"RemoteException"
if (jsonReader.Value == null || !((string)jsonReader.Value).Equals("RemoteException"))
{
throw new IOException(
$"Unexpected type of exception in JSON error output. Expected: RemoteException Actual: {jsonReader.Value}");
}
jsonReader.Read(); //StartObject {
do
{
jsonReader.Read();
if (jsonReader.TokenType.Equals(JsonToken.PropertyName))
{
switch ((string)jsonReader.Value)
{
case "exception":
jsonReader.Read();
resp.RemoteExceptionName = (string)jsonReader.Value;
break;
case "message":
jsonReader.Read();
resp.RemoteExceptionMessage = (string)jsonReader.Value;
break;
case "javaClassName":
jsonReader.Read();
resp.RemoteExceptionJavaClassName = (string)jsonReader.Value;
break;
}
}
} while (!jsonReader.TokenType.Equals(JsonToken.EndObject));
}
}
}
}
catch (Exception e)
{
resp.Ex = e;
//Store the actual remote response in a separate variable, since response can have illegal charcaters which will throw exception while setting them to headers
resp.RemoteErrorNonJsonResponse = $" Content-Type of error response: {contentType}. Error: {Encoding.UTF8.GetString(errorBytes, 0, errorBytesLength)}";
}
}