You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jan 14, 2018. It is now read-only.
I have requests with type Response. I need it, because the server can return object json type User (if is OK), but also it can return json object Error (if has http or other errors).
My requests work fine, where they loadDataFormNetwork, but if data in the cache - my app crashing.
And what important - app crashs inly on Lollipop 5.0 and higher.
If i change my code to use type User (without checking errors) - it works fine!
Please help!
My code:
====Activity=====
getSpiceManager().execute(oneUserRequest, "user_id_" + Global.USER_ID, DurationInMillis.ONE_WEEK, new UserRequestListener());
public final class UserRequestListener implements RequestListener { @OverRide
public void onRequestFailure(SpiceException spiceException) {
Toast.makeText(context, R.string.no_connect, Toast.LENGTH_SHORT).show();
} @OverRide
public void onRequestSuccess(final Response response) {
oneUserRequestFired = true;
TypedInput body = response.getBody();
Converter converter = new GsonConverter(new Gson());
try {
ApiError error = (ApiError) converter.fromBody(body, ApiError.class);
if (!error.check())
throw new ConversionException("not error");
error.go(context);
} catch (ConversionException e1) {
try {
User user = (User) converter.fromBody(body, User.class);
if (user != null) {
...........MY CODE................
} else
throw new ConversionException("Ошибка парсинга");
} catch (ConversionException e2) {
Toast.makeText(context, e2.toString(), Toast.LENGTH_LONG).show();
}
}
}
}
====REQUEST====
public class OneUserRequest extends RetrofitSpiceRequest<Response, WishesService> {
private final int user_id;
public OneUserRequest(int user_id) {
super(Response.class, WishesService.class);
this.user_id = user_id;
}
@Override
public Response loadDataFromNetwork() {
return getService().user(Global.APP_KEY, user_id, Global.AUTH_TOKEN);
}
}
====Service and API===== @get("/v1/user")
Response user(@query("app_key") String app_key, @query("id") int user_id, @query("access-token") String access_token);
@OverRide
public void onCreate() {
super.onCreate();
addRetrofitInterface(WishesService.class);
// Logging really causes the app to chug with this many requests
Ln.getConfig().setLoggingLevel(Log.VERBOSE);
}
@Override
public CacheManager createCacheManager(Application application) throws CacheCreationException {
CacheManager manager = new CacheManager();
// Order is important: by default, Retrofit persists all objects.
manager.addPersister(new RetrofitObjectPersisterFactory(application, getConverter(), getCacheFolder()));
return manager;
}
The text was updated successfully, but these errors were encountered:
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
I have requests with type Response. I need it, because the server can return object json type User (if is OK), but also it can return json object Error (if has http or other errors).
My requests work fine, where they loadDataFormNetwork, but if data in the cache - my app crashing.
And what important - app crashs inly on Lollipop 5.0 and higher.
If i change my code to use type User (without checking errors) - it works fine!
Please help!
My code:
====Activity=====
getSpiceManager().execute(oneUserRequest, "user_id_" + Global.USER_ID, DurationInMillis.ONE_WEEK, new UserRequestListener());
public final class UserRequestListener implements RequestListener {
@OverRide
public void onRequestFailure(SpiceException spiceException) {
Toast.makeText(context, R.string.no_connect, Toast.LENGTH_SHORT).show();
}
@OverRide
public void onRequestSuccess(final Response response) {
oneUserRequestFired = true;
TypedInput body = response.getBody();
Converter converter = new GsonConverter(new Gson());
try {
ApiError error = (ApiError) converter.fromBody(body, ApiError.class);
if (!error.check())
throw new ConversionException("not error");
====REQUEST====
public class OneUserRequest extends RetrofitSpiceRequest<Response, WishesService> {
private final int user_id;
}
====Service and API=====
@get("/v1/user")
Response user(@query("app_key") String app_key, @query("id") int user_id, @query("access-token") String access_token);
@OverRide
public void onCreate() {
super.onCreate();
addRetrofitInterface(WishesService.class);
// Logging really causes the app to chug with this many requests
Ln.getConfig().setLoggingLevel(Log.VERBOSE);
The text was updated successfully, but these errors were encountered: