{"record":{"id":"db300518054aa980","repo":"apple/pkl","slug":"badhttpstatuscode","errorCode":"badHttpStatusCode","errorMessage":"badHttpStatusCode","messagePattern":"badHttpStatusCode","errorType":"error_code","errorClass":"PackageLoadError","httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/packages/PackageResolvers.java","lineNumber":214,"sourceCode":"      if (!HttpUtils.isHttpUrl(uri)) {\n        throw new IllegalArgumentException(\"Expected HTTP(S) URL, but got: \" + uri);\n      }\n\n      // treat package assets as resources instead of modules\n      securityManager.checkReadResource(uri);\n      var request = HttpRequest.newBuilder(uri).build();\n      HttpResponse<InputStream> response;\n      try {\n        response =\n            httpClient.send(\n                request, BodyHandlers.ofInputStream(), securityManager::checkReadResource);\n      } catch (IOException e) {\n        throw new PackageLoadError(e, \"ioErrorMakingHttpGet\", uri, e.getMessage());\n      }\n      try {\n        HttpUtils.checkHasStatusCode200(response);\n      } catch (IOException e) {\n        throw new PackageLoadError(\"badHttpStatusCode\", response.statusCode(), response.uri());\n      }\n      return response.body();\n    }\n\n    protected IOException fileIsADirectory() {\n      // Sync with error message from `Files#readString(Path)`\n      return new IOException(\"Is a directory\");\n    }\n\n    protected abstract DependencyMetadata doGetDependencyMetadata(\n        PackageUri packageUri, @Nullable Checksums checksums)\n        throws IOException, SecurityManagerException;\n\n    protected abstract List<PathElement> doListElements(\n        PackageAssetUri uri, @Nullable Checksums checksums)\n        throws IOException, SecurityManagerException;\n\n    protected abstract boolean doHasElement(PackageAssetUri uri, @Nullable Checksums checksums)","sourceCodeStart":196,"sourceCodeEnd":232,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/packages/PackageResolvers.java#L196-L232","documentation":"PackageLoadError thrown when fetching a package from a remote repository over HTTP returns a status code other than 200. The library requires a successful HTTP response to download package contents; any other status (404, 403, 5xx, etc.) is rejected.","triggerScenarios":"Calling package resolution APIs that fetch a package zip over HTTPS (e.g. resolving a `package://` dependency) when the remote endpoint answers with a non-200 status; the check is `HttpUtils.checkHasStatusCode200(response)` in `openExternalUri`.","commonSituations":"Package URL is wrong or the package was removed/published under a different version (404); a private registry requires auth and returns 401/403; a proxy or CDN returns 502/503; corporate firewall intercepts the request.","solutions":["Check that the package URI/version is correct and the package exists on the remote repository","Run with logging or curl the exact response.uri() reported in the error to see the real status and body","If 401/403, configure credentials (e.g. environment variables or Maven settings for the repo)","If 5xx or proxy-related, retry later or fix proxy/VPN/firewall settings"],"exampleFix":"// before (PklProject dependencies)\n\"dependencies\": { \"my-pkg\": { \"package\": \"package://example.com/wrong/name@1.0.0\" } }\n// after\n\"dependencies\": { \"my-pkg\": { \"package\": \"package://example.com/correct/name@1.0.0\" } }","handlingStrategy":"try-catch","validationCode":"// pre-check the package endpoint before resolving\nvar conn = URI.create(\"https://example.com/registry/pkg@1.0.0\").toURL().openConnection();\nif (((HttpURLConnection) conn).getResponseCode() != 200) {\n  throw new IllegalStateException(\"Package endpoint unavailable: \" + ((HttpURLConnection) conn).getResponseCode());\n}","typeGuard":null,"tryCatchPattern":"try {\n  resolvePackage(uri);\n} catch (PackageLoadError e) {\n  if (\"badHttpStatusCode\".equals(e.getCode())) {\n    // inspect e.getMessage() for status + uri, apply fallback or abort\n  }\n}","preventionTips":["Pin exact package versions that you know exist on the registry","Verify registry URLs and credentials in CI before running resolution","Configure proxy/auth settings for private registries","curl the package URL once when setting up a new dependency"],"tags":["network","http","package-loading"],"backgroundTag":"http-error-response","analyzedSha":"f3efcbfc9b60d30053b0536d664948d7aa1b8673","analyzedAt":"2026-09-08T13:10:45.570Z","contentChangedAt":"2026-09-08T13:10:45.570Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}