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