hs-web/hsweb-framework · warning · NotAcceptableStatusException

not_acceptable_media_type

not_acceptable_media_type

Error message

error.not_acceptable_media_type

What it means

WebFlux's NotAcceptableStatusException is translated to HTTP 406 with code not_acceptable_media_type and the localized 'error.not_acceptable_media_type' message, with the supported media types returned as the result payload. It means the client's Accept header cannot be satisfied by any available message writer.

Solutions

  1. Change the Accept header to a type the server supports (listed in the 406 response result, typically application/json).
  2. Use Accept: */* if any supported representation is acceptable.
  3. If another format is genuinely required, add a message writer/encoder (e.g. Jackson XML) for it on the server.
  4. Check intermediaries that inject or rewrite Accept headers.

Example fix

// before
Accept: application/vnd.vendor+xml
// after
Accept: application/json
Defensive patterns

Strategy: validation

Validate before calling

const accept = 'application/json';
if (accept !== 'application/json' && accept !== '*/*') {
  console.warn(`Accept header ${accept} likely unsupported; use application/json`);
}

Try / catch

try {
  return await axios.get(url, { headers: { Accept: 'application/json' } });
} catch (e) {
  if (e.response && e.response.status === 406) {
    return axios.get(url, { headers: { Accept: '*/*' } }); // fallback
  }
  throw e;
}

Prevention

When it happens

Trigger: Sending Accept: application/xml (or an exotic type) to an endpoint that can only produce application/json; overly restrictive Accept patterns like application/*+json with no matching writer; versioned vendor MIME types the server doesn't register.

Common situations: API clients copy-pasted from different services with mismatched Accept headers; browser prefetch sending odd Accept values; gateways adding Accept headers.

Related errors


AI-assisted analysis of hs-web/hsweb-framework@b2cfc85a57 (2026-09-13). Data as JSON: /api/errors/d92efc71f47a8420. Report an issue: GitHub.

Appendix: source

Thrown at hsweb-commons/hsweb-commons-crud/src/main/java/org/hswebframework/web/crud/web/CommonErrorControllerAdvice.java:247

            .resolveThrowable(e, (err, msg) -> ResponseMessage.error(400, err.getCode(), msg));
    }

    @ExceptionHandler
    @ResponseStatus(HttpStatus.UNSUPPORTED_MEDIA_TYPE)
    public Mono<ResponseMessage<Object>> handleException(UnsupportedMediaTypeStatusException e) {
        log.warn(e.getLocalizedMessage(), e);

        return LocaleUtils
            .resolveMessageReactive("error.unsupported_media_type")
            .map(msg -> ResponseMessage
                .error(415, "unsupported_media_type", msg)
                .result(e.getSupportedMediaTypes()));
    }

    @ExceptionHandler
    @ResponseStatus(HttpStatus.NOT_ACCEPTABLE)
    public Mono<ResponseMessage<Object>> handleException(NotAcceptableStatusException e) {
        log.warn(e.getLocalizedMessage(), e);

        return LocaleUtils
            .resolveMessageReactive("error.not_acceptable_media_type")
            .map(msg -> ResponseMessage
                .error(406, "not_acceptable_media_type", msg)
                .result(e.getSupportedMediaTypes()));
    }

    @ExceptionHandler
    @ResponseStatus(HttpStatus.NOT_ACCEPTABLE)
    public Mono<ResponseMessage<Object>> handleException(MethodNotAllowedException e) {
        log.warn(e.getLocalizedMessage(), e);

        return LocaleUtils
            .resolveMessageReactive("error.method_not_allowed")
            .map(msg -> ResponseMessage
                .error(406, "method_not_allowed", msg)
                .result(e.getSupportedMethods()));

View on GitHub (pinned to b2cfc85a57)