Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
saravananmnm opened this issue Jul 4, 2019 · 14 comments

Comments

@saravananmnm
Copy link

[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)

@tejainece
Copy link
Member

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

@saravananmnm
Copy link
Author

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;
}

@jaumard
Copy link
Contributor

jaumard commented Jul 5, 2019

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

@saravananmnm
Copy link
Author

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

@jaumard
Copy link
Contributor

jaumard commented Jul 5, 2019

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

@saravananmnm
Copy link
Author

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;
}
}

@saravananmnm
Copy link
Author

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)

@jaumard
Copy link
Contributor

jaumard commented Jul 5, 2019

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

@tejainece
Copy link
Member

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.

@saravananmnm
Copy link
Author

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

converter is final variable. so we cant reassign.

@jaumard
Copy link
Contributor

jaumard commented Jul 5, 2019

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

@tejainece
Copy link
Member

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

@saravananmnm
Copy link
Author

@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.

@saravananmnm
Copy link
Author

kindly provide any code snippets

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants