{"record":{"id":"843a9348bac2dc7c","repo":"YMFE/yapi","slug":"http-status-response-status-swagger","errorCode":null,"errorMessage":"http status \"${response.status}\"获取数据失败，请确认 swaggerUrl 是否正确","messagePattern":"http status \"(.+?)\"获取数据失败，请确认 swaggerUrl 是否正确","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"exts/yapi-plugin-swagger-auto-sync/interfaceSyncUtils.js","lineNumber":210,"sourceCode":"     * @param {*} syncMode 合并模式\n     */\n    getSyncModeName(syncMode) {\n        if (syncMode == 'good') {\n            return '智能合并';\n        } else if (syncMode == 'normal') {\n            return '普通模式';\n        } else if (syncMode == 'merge') {\n            return '完全覆盖';\n        }\n        return '';\n    }\n\n    async getSwaggerContent(swaggerUrl) {\n        const axios = require('axios')\n        try {\n            let response = await axios.get(swaggerUrl);\n            if (response.status > 400) {\n                throw new Error(`http status \"${response.status}\"` + '获取数据失败，请确认 swaggerUrl 是否正确')\n            }\n            return response.data;\n        } catch (e) {\n            let response = e.response || {status: e.message || 'error'};\n            throw new Error(`http status \"${response.status}\"` + '获取数据失败，请确认 swaggerUrl 是否正确')\n        }\n    }\n\n}\n\nmodule.exports = syncUtils;","sourceCodeStart":192,"sourceCodeEnd":221,"githubUrl":"https://github.com/YMFE/yapi/blob/59bade3a8a43e7db077d38a4b0c7c584f30ddf8c/exts/yapi-plugin-swagger-auto-sync/interfaceSyncUtils.js#L192-L221","documentation":"getSwaggerContent fetches a swagger JSON document via axios. If the HTTP status is greater than 400, it throws this error; the message embeds the status so users can tell the swaggerUrl is unreachable or wrong.","triggerScenarios":"syncInterface calls getSwaggerContent with a swaggerUrl that responds with status > 400 (e.g. 404 wrong path, 401 auth required, 500 server crash).","commonSituations":"Swagger URL pointing to a UI page instead of the JSON spec; missing auth token on the swagger endpoint; firewall/proxy blocking the server-side request; typos in host/port.","solutions":["Open the swaggerUrl in a browser/curl from the server host and confirm it returns JSON with HTTP 200","Fix the URL path — use the raw spec endpoint (e.g. /v2/swagger.json), not the swagger UI page","Add required auth headers or make the spec endpoint publicly reachable for the YApi server","Check network/proxy settings on the YApi server"],"exampleFix":"// before\nsyncUrl: 'http://host/swagger-ui.html'\n// after\nsyncUrl: 'http://host/v2/api-docs'","handlingStrategy":"validation","validationCode":"async function assertSwaggerUrlOk(url){\n  const res = await fetch(url, { method: 'HEAD' }).catch(() => null);\n  if (!res || res.status > 400) throw new Error('swaggerUrl unreachable or status ' + (res && res.status));\n}","typeGuard":null,"tryCatchPattern":"try {\n  await syncInterface(swaggerUrl);\n} catch (e) {\n  if (/swaggerUrl/.test(e.message)) notifyAdmin('Fix swagger URL: ' + swaggerUrl);\n  else throw e;\n}","preventionTips":["Use the raw JSON spec URL, not the swagger UI page","Verify the URL from the YApi server host (curl) — not just your laptop","Confirm auth requirements on the spec endpoint","Re-check URLs after service migrations"],"tags":["network","http","swagger","sync"],"backgroundTag":"http-request-failed","analyzedSha":"59bade3a8a43e7db077d38a4b0c7c584f30ddf8c","analyzedAt":"2026-08-29T08:45:22.203Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}