iflytek/astron-agent · warning · HttpRequestMethodNotSupportedException

METHOD_NOT_ALLOWED

METHOD_NOT_ALLOWED

Error message

HTTP request method not supported exception: {}

What it means

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'.

Solutions

  1. Check the Allow header in the 405 response — it lists the methods the endpoint supports; switch the client to one of them.
  2. Compare the client's HTTP method with the controller mapping annotation (@GetMapping vs @PostMapping etc.) and fix the mismatch.
  3. If a route's verb was intentionally changed, update all callers or keep a compatible alias mapping.
  4. For HTML forms needing PUT/DELETE, use a hidden _method field with HttpPutFormContentFilter or switch to fetch/axios.
  5. Verify CORS preflight (OPTIONS) is handled if the error appears only from browsers.

Example fix

// before
axios.put('/api/agent/list') // 405: only GET mapped

// after
axios.get('/api/agent/list')
Defensive patterns

Strategy: validation

Validate before calling

// consult the OpenAPI spec / Allow header before calling
const allowed = ['GET', 'POST'];
if (!allowed.includes(method)) throw new Error(`Unsupported method ${method} for ${url}`);

Type guard

const isSupportedMethod = (m) => ['GET','POST','PUT','DELETE','PATCH'].includes(m.toUpperCase());

Try / catch

try {
  return await axios.request({ url, method });
} catch (e) {
  if (e.response?.status === 405) {
    const allow = e.response.headers['allow'];
    console.error(`Method ${method} not allowed; allowed: ${allow}`);
  } else throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of iflytek/astron-agent@5e758547a8 (2026-09-12). Data as JSON: /api/errors/b8dfc31136546f8b. Report an issue: GitHub.

Appendix: source

Thrown at console/backend/toolkit/src/main/java/com/iflytek/astron/console/toolkit/config/exception/handler/GlobalExceptionHandler.java:100

        String messageCode = "parameter.missing";
        log.warn("Missing request parameter exception: {}", messageCode);
        return ApiResult.error(ResponseEnum.PARAMETER_ERROR.getCode(), messageCode);
    }

    /** Handle HTTP message not readable exceptions */
    @ExceptionHandler(HttpMessageNotReadableException.class)
    @ResponseStatus(HttpStatus.BAD_REQUEST)
    public ApiResult<Void> handleHttpMessageNotReadableException(HttpMessageNotReadableException e) {
        log.warn("HTTP message not readable exception: {}", e.getMessage(), e);
        return ApiResult.error(ResponseEnum.BAD_REQUEST.getCode(), "parameter.illegal");
    }

    /** Handle HTTP request method not supported exceptions */
    @ExceptionHandler(HttpRequestMethodNotSupportedException.class)
    @ResponseStatus(HttpStatus.METHOD_NOT_ALLOWED)
    public ApiResult<Void> handleHttpRequestMethodNotSupportedException(HttpRequestMethodNotSupportedException e) {
        String messageCode = "http.method.not.supported";
        log.warn("HTTP request method not supported exception: {}", messageCode, e);
        return ApiResult.error(ResponseEnum.METHOD_NOT_ALLOWED.getCode(), messageCode);
    }

    /** Handle handler not found exceptions */
    @ExceptionHandler(NoHandlerFoundException.class)
    @ResponseStatus(HttpStatus.NOT_FOUND)
    public ApiResult<Void> handleNoHandlerFoundException(NoHandlerFoundException e) {
        String messageCode = "http.url.not.found";
        log.warn("Handler not found exception: {}", messageCode, e);
        return ApiResult.error(ResponseEnum.NOT_FOUND.getCode(), messageCode);
    }

    /** Handle other exceptions */
    @ExceptionHandler(Exception.class)
    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    public ApiResult<Void> handleException(Exception e) {
        log.error("Unknown exception: {}", e.getMessage(), e);
        return ApiResult.error(ResponseEnum.SYSTEM_ERROR.getCode(), "error.system");

View on GitHub (pinned to 5e758547a8)