Jaguar-dart/client

[ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: Exception: Converter for content type 'application/pdf' not found!

Opened this issue · 14 comments

[ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: Exception: Converter for content type 'application/pdf' not found!
E/flutter ( 8390): #0 ApiClient.decodeOne (package:jaguar_retrofit/client/client.dart:23:7)
E/flutter ( 8390):
E/flutter ( 8390): #1 _rootRunUnary (dart:async/zone.dart:1132:38)
E/flutter ( 8390): #2 _CustomZone.runUnary (dart:async/zone.dart:1029:19)
E/flutter ( 8390): #3 _FutureListener.handleValue (dart:async/future_impl.dart:126:18)
E/flutter ( 8390): #4 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:639:45)
E/flutter ( 8390): #5 Future._propagateToListeners (dart:async/future_impl.dart:668:32)
E/flutter ( 8390): #6 Future._complete (dart:async/future_impl.dart:473:7)
E/flutter ( 8390): #7 _SyncCompleter.complete (dart:async/future_impl.dart:51:12)
E/flutter ( 8390): #8 _AsyncAwaitCompleter.complete (dart:async-patch/async_patch.dart:28:18)
E/flutter ( 8390): #9 _completeOnAsyncReturn (dart:async-patch/async_patch.dart:294:13)
E/flutter ( 8390): #10 AsyncStringResponse.run. (package:jaguar_resty/response/response.dart)
E/flutter ( 8390):
E/flutter ( 8390): #11 _rootRunUnary (dart:async/zone.dart:1132:38)
E/flutter ( 8390): #12 _CustomZone.runUnary (dart:async/zone.dart:1029:19)
E/flutter ( 8390): #13 _FutureListener.handleValue (dart:async/future_impl.dart:126:18)
E/flutter ( 8390): #14 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:639:45)
E/flutter ( 8390): #15 Future._propagateToListeners (dart:async/future_impl.dart:668:32)
E/flutter ( 8390): #16 Future._complete (dart:async/future_impl.dart:473:7)
E/flutter ( 8390): #17 _SyncCompleter.complete (dart:async/future_impl.dart:51:12)
E/flutter ( 8390): #18 _AsyncAwaitCompleter.complete (dart:async-patch/async_patch.dart:28:18)
E/flutter ( 8390): #19 _completeOnAsyncReturn (dart:async-patch/async_patch.dart:294:13)
E/flutter ( 8390): #20 Get.go. (package:jaguar_resty/routes/routes.dart)
E/flutter ( 8390):
E/flutter ( 8390): #21 _rootRunUnary (dart:async/zone.dart:1132:38)
E/flutter ( 8390): #22 _CustomZone.runUnary (dart:async/zone.dart:1029:19)
E/flutter ( 8390): #23 _FutureListener.handleValue (dart:async/future_impl.dart:126:18)
E/flutter ( 8390): #24 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:639:45)
E/flutter ( 8390): #25 Future._propagateToListeners (dart:async/future_impl.dart:668:32)
E/flutter ( 8390): #26 Future._completeWithValue (dart:async/future_impl.dart:483:5)
E/flutter ( 8390): #27 Future._asyncComplete. (dart:async/future_impl.dart:513:7)
E/flutter ( 8390): #28 _rootRun (dart:async/zone.dart:1124:13)
E/flutter ( 8390): #29 _CustomZone.run (dart:async/zone.dart:1021:19)
E/flutter ( 8390): #30 _CustomZone.runGuarded (dart:async/zone.dart:923:7)
E/flutter ( 8390): #31 _CustomZone.bindCallbackGuarded. (dart:async/zone.dart:963:23)
E/flutter ( 8390): #32 _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
E/flutter ( 8390): #33 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)

Originally posted by @saravananmnm in #42 (comment)

@saravananmnm can you please provide retrofit definition of this route?

ApiInterface getBaseApi(final JsonRepo repo) {
resty.globalClient = IOClient();
apiInterface = ApiInterface(Route(base_esearch_test_url)
..before((req) {
print(req.getUrl);
print(req.getHeaders);
})
..after((res) {
print(res.request.url);
print(res.statusCode);
/* if (Platform.isAndroid)
Print.LogPrint(res.body.toString());
else
debugPrint(res.body);*/
}))
..jsonConverter = repo;
return apiInterface;
}

You set only jsonConverter which is for json, not for application/pdf,
You need to specify a converter for that content type by setting converters

actually response is binary stream, how can i handle that?

Same way :) use the right converter for the right content type, not sure jaguar have a binary stream converter so you might need to create your own

ApiInterface getBaseApiPdf() {
apiInterface = ApiInterface(Route(base_esearch_test_url).withClient(
RestyIOClient(
HttpClient()
..connectionTimeout = const Duration(seconds: 60)
..idleTimeout = const Duration(seconds: 30)
..userAgent = 'Test Agent',
)..timeout = Duration(seconds: 2),
)
..before((req) {
print(req.getUrl);
print(req.getHeaders);
})
..after((res) {
res.headers[MimeTypes.pdf];
print(res.request.url);
print(res.statusCode);
/* if (Platform.isAndroid)
Print.LogPrint(res.body);
else
debugPrint(res.body);*/
}))
..converters[MimeTypes.pdf];
return apiInterface;
}
}

Still am getting error. can u tell the detailed script

[ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: Exception: Converter for content type 'application/pdf' not found!
E/flutter ( 5985): #0 ApiClient.decodeOne (package:jaguar_retrofit/client/client.dart:23:7)

It's because you didn't use converters correctly,
you need to give the converter like: ..converters = { MimeTypes.pdf: myBinaryConverter}

I don't see retrofit spec for your route. Also please format the code and use Markdown code blocks.

I will take a look at it. If the response body is not deserialized, you should not get this error because jaguar should not try to serialize your data.

However if you want to deserialize the response to PDF object, might need deserializing and have to provide a converter.

you need to give the converter like: ..converters = { MimeTypes.pdf: myBinaryConverter}

converter is final variable. so we cant reassign.

You're right :) it need to be passed in the constructor as it's final my bad

@saravananmnm You shouldn't need a converter if you just want bytes (List).

@multipart
@post("api/Service/Documents/InsertOrUpdateforVDMGPSInstallation")
Observable postVdmGpsInstallationImage(@part("json") RequestBody json, @part MultipartBody.Part image);

above code is java retrofit2 with rxjava.
I need convert above code to jaguar_retrofit, kindly send any code snippets.

kindly provide any code snippets