1 package io.bytom.offline.exception;
\r
3 import com.squareup.okhttp.Response;
\r
5 import java.io.IOException;
\r
8 * ConnectivityException wraps errors due to connectivity issues with the server.
\r
10 public class ConnectivityException extends BytomException {
\r
12 * Initializes exception with its message attribute.
\r
14 * @param resp the server response used to create error message
\r
16 public ConnectivityException(Response resp) {
\r
17 super(formatMessage(resp));
\r
21 * Parses the the server response into a detailed error message.
\r
23 * @param resp the server response
\r
24 * @return detailed error message
\r
26 private static String formatMessage(Response resp) {
\r
28 "Response HTTP header field Chain-Request-ID is unset. There may be network issues. Please check your local network settings.";
\r
29 // TODO(kr): include client-generated reqid here once we have that.
\r
32 body = resp.body().string();
\r
33 } catch (IOException ex) {
\r
34 body = "[unable to read response body: " + ex.toString() + "]";
\r
36 return String.format("%s status=%d body=%s", s, resp.code(), body);
\r