service에서 Call<Body> 형태로 데이터를 반환하도록 하면, 해당 서비스 함수를 실행하여 Call 객체를 받을 수 있다. 이 Call 객체는 enqueue 메써드를 가지는데, enqueue 메써드를 통해 레트로핏의 작업 큐에 call을 전달할 수 있다. 작업 큐에서 완료된 call은 callback 인터페이스를 요청한다.
public interface Callback<T> {
/**
* Invoked for a received HTTP response.
*
* <p>Note: An HTTP response may still indicate an application-level failure such as a 404 or 500.
* Call {@link Response#isSuccessful()} to determine if the response indicates success.
*/
void onResponse(Call<T> call, Response<T> response);
/**
* Invoked when a network exception occurred talking to the server or when an unexpected exception
* occurred creating the request or processing the response.
*/
void onFailure(Call<T> call, Throwable t);
}
Response가 도착하면 onResponse가 실행되고, response가 도착하지 못한 경우 OnFailure가 실행된다.
response가 도착하면, status code에 맞게 동작을 실행할 수 있다.