Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Retrofitting Control Flow

Retrofitting Control Flow

How does error handling influence the larger design of app architecture? This talk will attempt to answer this, using the speaker’s experience upgrading the Electric Objects Android applications from Retrofit v1.9 to the v2.0-beta2.

We will cover the deeper architectural ramifications of error strategies, particularly focusing on the question ‘what is the impact of exceptions on control flow?’ using examples from v1 & v2 of Square’s Retrofit library and the supporting code that Electric Objects uses to wrap these network calls.

Presented at Square Engineering's Android Spring Cleaning event on March 10th. https://www.showclix.com/event/square-new-york-presents

NeiL saitug

March 10, 2016
Tweet

More Decks by NeiL saitug

Other Decks in Programming

Transcript

  1. try { request.makeRequest(); // if you reach this, request succeeded!

    return request; } catch (RetrofitError error) { Response errorResponse = error.getResponse(); switch (error.getKind()) { case NETWORK: case HTTP: case CONVERSION: case UNEXPECTED: // deal with error }
  2. void List<Shoe> onMakeRequest() { List<Shoe> myFavoriteShoes = // call to

    get my shoes List<Shoe> friendsFavoriteShoes = // call to get friend's shoes return myFavoriteShoes.addAll(friendsFavoriteShoes); }
  3. try { response = request.makeRequest(); if (response.isSuccess()) { return request;

    } else { // server error? } } catch (IOException e) { // network error } catch (Exception ex) { // unexpected/parse error throw ex; }
  4. v1 Success: • connected to the server • received a

    successful response • parsed the response successfully • here's your object.
  5. void List<Shoe> onMakeRequest() { Response shoesResponse = // call to

    get my shoes if (!shoesResponse.isSuccess()) return error!!; Response friendsResponse = // call to get friend's shoes if (!friendResponse.isSuccess()) return error!!; // otherwise proceed. }