{"record":{"id":"e42983c32c2b061e","repo":"arduino/Arduino","slug":"received-invalid-http-status-code-from-server-re","errorCode":null,"errorMessage":"Received invalid http status code from server: {resp}","messagePattern":"Received invalid http status code from server: (.+?)","errorType":"http","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"arduino-core/src/cc/arduino/utils/network/FileDownloader.java","lineNumber":222,"sourceCode":"    }\n    return Optional.empty();\n  }\n\n  private void openConnectionAndFillTheFile(boolean noResume) throws Exception {\n    initialSize = outputFile.length();\n    if (noResume && initialSize > 0) {\n      // delete file and restart downloading\n      Files.deleteIfExists(outputFile.toPath());\n      initialSize = 0;\n    }\n\n    final HttpURLConnection connection = new HttpConnectionManager(downloadUrl)\n      .makeConnection((c) -> setDownloaded(0));\n    final int resp = connection.getResponseCode();\n\n    if (resp < 200 || resp >= 300) {\n      Files.deleteIfExists(outputFile.toPath());\n      throw new IOException(\"Received invalid http status code from server: \" + resp);\n    }\n\n    RandomAccessFile randomAccessOutputFile = null;\n    try {\n      // Open file and seek to the end of it\n      randomAccessOutputFile = new RandomAccessFile(outputFile, \"rw\");\n      randomAccessOutputFile.seek(initialSize);\n      readStreamCopyTo(randomAccessOutputFile, connection);\n    } finally {\n      IOUtils.closeQuietly(randomAccessOutputFile);\n    }\n\n  }\n\n  private void readStreamCopyTo(RandomAccessFile randomAccessOutputFile, HttpURLConnection connection) throws Exception {\n    InputStream stream = null;\n    try {\n      // Check for valid content length.","sourceCodeStart":204,"sourceCodeEnd":240,"githubUrl":"https://github.com/arduino/Arduino/blob/a0df6e0e83b652c72bc78b0a1376c54d6ebc3bee/arduino-core/src/cc/arduino/utils/network/FileDownloader.java#L204-L240","documentation":"FileDownloader throws this IOException when the HTTP response code of the download request falls outside the 200-299 range. The partial output file is deleted first so no corrupt download remains, then the error names the exact status code received.","triggerScenarios":"downloadFile() calls openConnectionAndFillTheFile(), which calls HttpConnectionManager.makeConnection(); connection.getResponseCode() returns < 200 or >= 300 (e.g. 403 Forbidden, 404 Not Found, 500, or a non-handled 3xx).","commonSituations":"Download URL points to a moved/removed resource (404); server or CDN blocks the client (403); proxy misconfiguration (CustomProxySelector) returning an error page; transient 5xx during heavy load.","solutions":["Verify the download URL is correct and reachable (open it in a browser or curl -I)","Check proxy settings in Arduino preferences if behind a corporate proxy","Retry after a delay for transient 5xx responses","Check authentication/firewall rules if the server returns 403"],"exampleFix":"// before: no pre-check\ndownloader.downloadFile(new URL(url), file, false);\n// after: HEAD-check and retry\nHttpURLConnection c = (HttpURLConnection) new URL(url).openConnection();\nc.setRequestMethod(\"HEAD\");\nif (c.getResponseCode() < 200 || c.getResponseCode() >= 300) throw new IOException(\"URL unavailable: \" + c.getResponseCode());\ndownloader.downloadFile(new URL(url), file, false);","handlingStrategy":"retry","validationCode":"HttpURLConnection c = (HttpURLConnection) url.openConnection();\nc.setRequestMethod(\"HEAD\");\nif (c.getResponseCode() < 200 || c.getResponseCode() >= 300)\n  throw new IllegalStateException(\"URL not downloadable: \" + c.getResponseCode());","typeGuard":null,"tryCatchPattern":"try {\n  downloader.downloadFile(url, file, false);\n} catch (IOException e) {\n  if (e.getMessage().contains(\"Received invalid http status code\")) {\n    // check proxy settings / retry with backoff\n    configureProxy();\n    downloader.downloadFile(url, file, false);\n  } else throw e;\n}","preventionTips":["Validate download URLs with a HEAD request before starting long downloads","Configure proxy settings correctly in preferences when behind a firewall","Retry 5xx failures with exponential backoff","Keep URLs pinned to stable release endpoints that do not 404"],"tags":["network","http","download","status-code"],"backgroundTag":"http-error-status","analyzedSha":"a0df6e0e83b652c72bc78b0a1376c54d6ebc3bee","analyzedAt":"2026-09-06T10:13:38.901Z","contentChangedAt":"2026-09-06T10:13:38.901Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}