Example #1
0
  public void checkResponse(Response<?> response) {

    if (!response.isSuccessful()) {

      String errorBody;
      try {
        errorBody = response.errorBody().string();
      } catch (Exception e) {
        throw new TembaException(e);
      }

      // make a note of the error in our log
      Surveyor.LOG.d(errorBody);

      // see if the server had anything interesting to say
      JsonObject error = JsonUtils.getGson().fromJson(errorBody, JsonObject.class);
      if (error != null) {
        JsonElement detail = error.get("detail");
        if (detail != null) {

          String message = detail.getAsString();
          if (message.equals("Invalid token")) {
            message = "Login failure, please logout and try again.";
          }
          throw new ResponseException(message);
        }
      }

      throw new TembaException("Error reading response");
    }
  }
Example #2
0
 /** Get the flow definition, or null if it fails */
 public Definitions getLegacyFlowDefinition(String flowUuid) {
   try {
     Response<FlowDefinition> flowDefinitionResponse =
         m_api.getLegacyFlowDefinition(getToken(), flowUuid).execute();
     checkResponse(flowDefinitionResponse);
     FlowDefinition def = flowDefinitionResponse.body();
     Definitions definitions = new Definitions();
     definitions.version = def.version;
     definitions.flows = new ArrayList<>();
     definitions.flows.add(def);
     return definitions;
   } catch (IOException e) {
     Surveyor.LOG.e("Error fetching flow definition", e);
   }
   return null;
 }