(final Callback<T> callback)
| 116 | } |
| 117 | |
| 118 | @Override |
| 119 | public void enqueue(final Callback<T> callback) { |
| 120 | Objects.requireNonNull(callback, "callback == null"); |
| 121 | |
| 122 | okhttp3.Call call; |
| 123 | Throwable failure; |
| 124 | |
| 125 | synchronized (this) { |
| 126 | if (executed) throw new IllegalStateException("Already executed."); |
| 127 | executed = true; |
| 128 | |
| 129 | call = rawCall; |
| 130 | failure = creationFailure; |
| 131 | if (call == null && failure == null) { |
| 132 | try { |
| 133 | call = rawCall = createRawCall(); |
| 134 | } catch (Throwable t) { |
| 135 | throwIfFatal(t); |
| 136 | failure = creationFailure = t; |
| 137 | } |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | if (failure != null) { |
| 142 | callback.onFailure(this, failure); |
| 143 | return; |
| 144 | } |
| 145 | |
| 146 | if (canceled) { |
| 147 | call.cancel(); |
| 148 | } |
| 149 | |
| 150 | call.enqueue( |
| 151 | new okhttp3.Callback() { |
| 152 | @Override |
| 153 | public void onResponse(okhttp3.Call call, okhttp3.Response rawResponse) { |
| 154 | Response<T> response; |
| 155 | try { |
| 156 | response = parseResponse(rawResponse); |
| 157 | } catch (Throwable e) { |
| 158 | throwIfFatal(e); |
| 159 | callFailure(e); |
| 160 | return; |
| 161 | } |
| 162 | |
| 163 | try { |
| 164 | callback.onResponse(OkHttpCall.this, response); |
| 165 | } catch (Throwable t) { |
| 166 | throwIfFatal(t); |
| 167 | t.printStackTrace(); // TODO this is not great |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | @Override |
| 172 | public void onFailure(okhttp3.Call call, IOException e) { |
| 173 | callFailure(e); |
| 174 | } |
| 175 |
nothing calls this directly
no test coverage detected