@Override
  public Object decode(Response response, Type type) throws IOException {
    JsonAdapter<Object> jsonAdapter = moshi.adapter(type);

    if (response.status() == 404 || response.status() == 204)
      return Util.emptyValueOf(type);
    if (response.body() == null)
      return null;

    try (BufferedSource source = Okio.buffer(Okio.source(response.body().asInputStream()))) {
      if (source.exhausted()) {
        return null; // empty body
      }
      return jsonAdapter.fromJson(source);
    } catch (JsonDataException e) {
      if (e.getCause() != null && e.getCause() instanceof IOException) {
        throw (IOException) e.getCause();
      }
      throw e;
    }
  }
@Test
  void notFoundDecodesToEmpty() throws Exception {
    Response response = Response.builder()
        .status(404)
        .reason("NOT FOUND")
        .headers(Collections.emptyMap())
        .request(Request.create(Request.HttpMethod.GET, "/api", Collections.emptyMap(), null,
            Util.UTF_8))
        .build();
    assertThat((byte[]) new MoshiDecoder().decode(response, byte[].class)).isEmpty();
  }