{"record":{"id":"b8dfc31136546f8b","repo":"iflytek/astron-agent","slug":"method-not-allowed","errorCode":"METHOD_NOT_ALLOWED","errorMessage":"HTTP request method not supported exception: {}","messagePattern":"HTTP request method not supported exception: (.+?)","errorType":"http","errorClass":"HttpRequestMethodNotSupportedException","httpStatus":405,"severity":"warning","filePath":"console/backend/toolkit/src/main/java/com/iflytek/astron/console/toolkit/config/exception/handler/GlobalExceptionHandler.java","lineNumber":100,"sourceCode":"        String messageCode = \"parameter.missing\";\n        log.warn(\"Missing request parameter exception: {}\", messageCode);\n        return ApiResult.error(ResponseEnum.PARAMETER_ERROR.getCode(), messageCode);\n    }\n\n    /** Handle HTTP message not readable exceptions */\n    @ExceptionHandler(HttpMessageNotReadableException.class)\n    @ResponseStatus(HttpStatus.BAD_REQUEST)\n    public ApiResult<Void> handleHttpMessageNotReadableException(HttpMessageNotReadableException e) {\n        log.warn(\"HTTP message not readable exception: {}\", e.getMessage(), e);\n        return ApiResult.error(ResponseEnum.BAD_REQUEST.getCode(), \"parameter.illegal\");\n    }\n\n    /** Handle HTTP request method not supported exceptions */\n    @ExceptionHandler(HttpRequestMethodNotSupportedException.class)\n    @ResponseStatus(HttpStatus.METHOD_NOT_ALLOWED)\n    public ApiResult<Void> handleHttpRequestMethodNotSupportedException(HttpRequestMethodNotSupportedException e) {\n        String messageCode = \"http.method.not.supported\";\n        log.warn(\"HTTP request method not supported exception: {}\", messageCode, e);\n        return ApiResult.error(ResponseEnum.METHOD_NOT_ALLOWED.getCode(), messageCode);\n    }\n\n    /** Handle handler not found exceptions */\n    @ExceptionHandler(NoHandlerFoundException.class)\n    @ResponseStatus(HttpStatus.NOT_FOUND)\n    public ApiResult<Void> handleNoHandlerFoundException(NoHandlerFoundException e) {\n        String messageCode = \"http.url.not.found\";\n        log.warn(\"Handler not found exception: {}\", messageCode, e);\n        return ApiResult.error(ResponseEnum.NOT_FOUND.getCode(), messageCode);\n    }\n\n    /** Handle other exceptions */\n    @ExceptionHandler(Exception.class)\n    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)\n    public ApiResult<Void> handleException(Exception e) {\n        log.error(\"Unknown exception: {}\", e.getMessage(), e);\n        return ApiResult.error(ResponseEnum.SYSTEM_ERROR.getCode(), \"error.system\");","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/console/backend/toolkit/src/main/java/com/iflytek/astron/console/toolkit/config/exception/handler/GlobalExceptionHandler.java#L82-L118","documentation":"Spring MVC throws HttpRequestMethodNotSupportedException when a mapped handler exists for the URL but not for the request's HTTP method (e.g. POST to a GET-only endpoint). The handler responds with HTTP 405 METHOD_NOT_ALLOWED and message code 'http.method.not.supported'.","triggerScenarios":"Calling an endpoint with the wrong verb: POST to a @GetMapping route, PUT to a @PostMapping route, or HEAD/OPTIONS where only GET is mapped.","commonSituations":"Frontend fetch/axios method typo; API version changed a route's verb; HTML form only supports GET/POST used against PUT/DELETE endpoints; proxy/gateway rewriting methods; browser preflight hitting a route without OPTIONS support.","solutions":["Check the Allow header in the 405 response — it lists the methods the endpoint supports; switch the client to one of them.","Compare the client's HTTP method with the controller mapping annotation (@GetMapping vs @PostMapping etc.) and fix the mismatch.","If a route's verb was intentionally changed, update all callers or keep a compatible alias mapping.","For HTML forms needing PUT/DELETE, use a hidden _method field with HttpPutFormContentFilter or switch to fetch/axios.","Verify CORS preflight (OPTIONS) is handled if the error appears only from browsers."],"exampleFix":"// before\naxios.put('/api/agent/list') // 405: only GET mapped\n\n// after\naxios.get('/api/agent/list')","handlingStrategy":"validation","validationCode":"// consult the OpenAPI spec / Allow header before calling\nconst allowed = ['GET', 'POST'];\nif (!allowed.includes(method)) throw new Error(`Unsupported method ${method} for ${url}`);","typeGuard":"const isSupportedMethod = (m) => ['GET','POST','PUT','DELETE','PATCH'].includes(m.toUpperCase());","tryCatchPattern":"try {\n  return await axios.request({ url, method });\n} catch (e) {\n  if (e.response?.status === 405) {\n    const allow = e.response.headers['allow'];\n    console.error(`Method ${method} not allowed; allowed: ${allow}`);\n  } else throw e;\n}","preventionTips":["Type HTTP calls with a generated client so verbs are constrained per route.","Check the Allow header on 405s — it documents the supported methods.","Update all callers whenever a route's verb changes in the backend.","Use fetch/axios (not HTML forms) for PUT/DELETE requests."],"tags":["http","spring-mvc","method-not-allowed","rest"],"backgroundTag":"unexpected-http-status","analyzedSha":"5e758547a83371a5a4b29dadf4ac03e8dd527635","analyzedAt":"2026-09-12T08:03:51.356Z","contentChangedAt":"2026-09-12T08:03:51.356Z","schemaVersion":2},"datasetVersion":"2026-09-19T12:17:13.211Z"}