{"record":{"id":"11efa9e523742745","repo":"bumptech/glide","slug":"failed-to-get-a-response-message","errorCode":null,"errorMessage":"Failed to get a response message","messagePattern":"Failed to get a response message","errorType":"http","errorClass":"HttpException","httpStatus":null,"severity":"warning","filePath":"library/src/main/java/com/bumptech/glide/load/data/HttpUrlFetcher.java","lineNumber":130,"sourceCode":"        throw new HttpException(\"Received empty or null redirect url\", statusCode);\n      }\n      URL redirectUrl;\n      try {\n        redirectUrl = new URL(url, redirectUrlString);\n      } catch (MalformedURLException e) {\n        throw new HttpException(\"Bad redirect url: \" + redirectUrlString, statusCode, e);\n      }\n      // Closing the stream specifically is required to avoid leaking ResponseBodys in addition\n      // to disconnecting the url connection below. See #2352.\n      cleanup();\n      return loadDataWithRedirects(redirectUrl, redirects + 1, url, headers);\n    } else if (statusCode == INVALID_STATUS_CODE) {\n      throw new HttpException(statusCode);\n    } else {\n      try {\n        throw new HttpException(urlConnection.getResponseMessage(), statusCode);\n      } catch (IOException e) {\n        throw new HttpException(\"Failed to get a response message\", statusCode, e);\n      }\n    }\n  }\n\n  private static int getHttpStatusCodeOrInvalid(HttpURLConnection urlConnection) {\n    try {\n      return urlConnection.getResponseCode();\n    } catch (IOException e) {\n      if (Log.isLoggable(TAG, Log.DEBUG)) {\n        Log.d(TAG, \"Failed to get a response code\", e);\n      }\n    }\n    return INVALID_STATUS_CODE;\n  }\n\n  private HttpURLConnection buildAndConfigureConnection(URL url, Map<String, String> headers)\n      throws HttpException {\n    HttpURLConnection urlConnection;","sourceCodeStart":112,"sourceCodeEnd":148,"githubUrl":"https://github.com/bumptech/glide/blob/eb14a895d8f866e6a08c3e19d50ea3bd2c12c20a/library/src/main/java/com/bumptech/glide/load/data/HttpUrlFetcher.java#L112-L148","documentation":"When the HTTP response has a non-OK, non-redirect status code (e.g., 404, 500), HttpUrlFetcher attempts to include the server's response message via urlConnection.getResponseMessage(). If that call throws an IOException (response message unavailable or unreadable), the secondary exception 'Failed to get a response message' wraps it, still carrying the original status code. This is a secondary failure: the real problem is the original HTTP error status.","triggerScenarios":"Server returns a 4xx/5xx error and then closes the connection before the response message can be read. The HttpURLConnection implementation cannot extract the reason phrase from the response. Connection drops after the status line but before the full headers.","commonSituations":"Servers that return an error status and immediately close the socket. Aggressive load balancers that reset connections on error. Android's default HttpURLConnection behaving inconsistently across OEM implementations.","solutions":["The underlying issue is the HTTP error status code; check getStatusCode() on the caught HttpException","Fix the server to return proper error responses with complete headers","Integrate OkHttp for more robust HTTP response parsing","Handle the HttpException in RequestListener and display an appropriate fallback"],"exampleFix":"// before\nGlide.with(context).load(url).into(imageView);\n// after — inspect status code and handle\nGlide.with(context)\n  .load(url)\n  .listener(new RequestListener<Drawable>() {\n    @Override public boolean onLoadFailed(GlideException e, Object m, Target<Drawable> t, boolean i) {\n      for (Throwable cause : e.getRootCauses()) {\n        if (cause instanceof HttpException) {\n          Log.w(TAG, \"HTTP error, status: \" + ((HttpException) cause).getStatusCode());\n        }\n      }\n      return false;\n    }\n    @Override public boolean onResourceReady(Drawable r, Object m, Target<Drawable> t, DataSource d, boolean i) { return false; }\n  })\n  .error(R.drawable.placeholder)\n  .into(imageView);","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"Glide.with(context)\n  .load(url)\n  .error(R.drawable.placeholder)\n  .listener(new RequestListener<Drawable>() {\n    @Override public boolean onLoadFailed(GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {\n      for (Throwable cause : e.getRootCauses()) {\n        if (cause instanceof HttpException) {\n          int statusCode = ((HttpException) cause).getStatusCode();\n          // The real issue is the HTTP error status; 'Failed to get a response message' is secondary\n          Log.w(TAG, \"HTTP error \" + statusCode + \" for \" + model);\n        }\n      }\n      return false;\n    }\n    @Override public boolean onResourceReady(Drawable r, Object m, Target<Drawable> t, DataSource d, boolean i) { return false; }\n  })\n  .into(imageView);","preventionTips":["Inspect getStatusCode() on the caught HttpException to find the real HTTP error","Integrate OkHttp for more robust HTTP response parsing","Handle non-200 HTTP statuses gracefully with appropriate placeholders","Monitor server error rates to catch 4xx/5xx spikes"],"tags":["glide","http","network","io"],"backgroundTag":null,"analyzedSha":"eb14a895d8f866e6a08c3e19d50ea3bd2c12c20a","analyzedAt":"2026-08-14T01:43:54.821Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}