{"record":{"id":"a497891f27071b32","repo":"alibaba/nacos","slug":"http-response-getstatuscode-when-fetching","errorCode":null,"errorMessage":"HTTP  + response.getStatusCode() +  when fetching  + response.getUrl()","messagePattern":"HTTP  \\+ response\\.getStatusCode\\(\\) \\+  when fetching  \\+ response\\.getUrl\\(\\)","errorType":"http","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"plugin-default-impl/nacos-default-ai-importer-plugin/src/main/java/com/alibaba/nacos/plugin/ai/importer/defaultimpl/skill/SkillsShImportService.java","lineNumber":128,"sourceCode":"    \n    SkillsShImportService(String endpoint, int maxItemCount, long maxArtifactSize,\n        DefaultImportHttpClient httpClient) {\n        this.endpoint = endpoint;\n        this.maxItemCount = maxItemCount > 0 ? maxItemCount : DEFAULT_MAX_FILE_COUNT;\n        this.maxArtifactSize = maxArtifactSize;\n        this.httpClient = httpClient;\n    }\n    \n    @Override\n    public AiResourceImportCandidatePage search(AiResourceImportContext context)\n        throws NacosException {\n        try {\n            String apiRoot = resolveApiRoot();\n            int resultLimit = resolveLimit(context.getLimit());\n            ImportHttpResponse response = fetchUrl(searchUrl(apiRoot,\n                resolveQuery(context.getQuery()), resolveSearchFetchLimit(resultLimit)));\n            if (!response.isSuccess()) {\n                throw new IllegalStateException(\n                    \"HTTP \" + response.getStatusCode() + \" when fetching \" + response.getUrl());\n            }\n            SkillsShSearchResponse searchResponse =\n                JacksonUtils.toObj(response.getBody(), SkillsShSearchResponse.class);\n            AiResourceImportCandidatePage result = new AiResourceImportCandidatePage();\n            result.setItems(toCandidates(apiRoot, searchResponse, resultLimit));\n            result.setHasMore(false);\n            result.setNextCursor(null);\n            return result;\n        } catch (NacosException e) {\n            throw e;\n        } catch (Exception e) {\n            throw dataAccess(\"Search skills.sh source failed: \" + e.getMessage(), e);\n        }\n    }\n    \n    @Override\n    public AiResourceImportArtifact fetch(AiResourceImportContext context,","sourceCodeStart":110,"sourceCodeEnd":146,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/plugin-default-impl/nacos-default-ai-importer-plugin/src/main/java/com/alibaba/nacos/plugin/ai/importer/defaultimpl/skill/SkillsShImportService.java#L110-L146","documentation":"Thrown inside SkillsShImportService.search() when the skills.sh search HTTP call returns a non-success status. Because the method wraps non-NacosException errors via dataAccess(), the caller actually receives a NacosException whose message is 'Search skills.sh source failed: HTTP {code} when fetching {url}'. The original IllegalStateException carries the code and URL.","triggerScenarios":"search() calls fetchUrl(searchUrl(...)); response.isSuccess() is false; the IllegalStateException is thrown, then caught by catch(Exception e) and rethrown as dataAccess('Search skills.sh source failed: ...').","commonSituations":"The skills.sh API root is misconfigured or unreachable; the service is rate-limiting (429) or down (5xx); an invalid query string triggers a 400; egress firewall blocks skills.sh.","solutions":["Verify the skills.sh API root endpoint configured for the importer.","Check skills.sh service availability and retry transient 5xx/429 responses.","Sanitize/encode the search query to avoid 400-level rejections."],"exampleFix":"// before\nAiResourceImportContext ctx = ...;\nctx.setQuery(\"a b c&d\"); // unencoded, may cause 400\nimporter.search(ctx);\n\n// after\nctx.setQuery(URLEncoder.encode(\"a b c&d\", StandardCharsets.UTF_8));\nimporter.search(ctx);","handlingStrategy":"try-catch","validationCode":"// Validate the skills.sh API root and encode the query before searching.\nURI root = URI.create(resolveApiRoot());\nif (!root.isAbsolute()) throw new IllegalArgumentException(\"skills.sh apiRoot must be absolute\");\nString q = URLEncoder.encode(context.getQuery(), StandardCharsets.UTF_8);","typeGuard":null,"tryCatchPattern":"try {\n    return importer.search(context);\n} catch (NacosException e) {\n    if (e.getMessage().contains(\"skills.sh source failed\")) {\n        // surface a user-friendly 'source unavailable, retry later' message\n    }\n    throw e;\n}","preventionTips":["URL-encode the search query to avoid 400s.","Verify the configured skills.sh API root is correct and reachable.","Retry transient 5xx/429; cache successful search results briefly."],"tags":["ai-registry","skill","network","http","importer"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}