{"record":{"id":"d92efc71f47a8420","repo":"hs-web/hsweb-framework","slug":"not-acceptable-media-type","errorCode":"not_acceptable_media_type","errorMessage":"error.not_acceptable_media_type","messagePattern":"error\\.not_acceptable_media_type","errorType":"http","errorClass":"NotAcceptableStatusException","httpStatus":406,"severity":"warning","filePath":"hsweb-commons/hsweb-commons-crud/src/main/java/org/hswebframework/web/crud/web/CommonErrorControllerAdvice.java","lineNumber":247,"sourceCode":"            .resolveThrowable(e, (err, msg) -> ResponseMessage.error(400, err.getCode(), msg));\n    }\n\n    @ExceptionHandler\n    @ResponseStatus(HttpStatus.UNSUPPORTED_MEDIA_TYPE)\n    public Mono<ResponseMessage<Object>> handleException(UnsupportedMediaTypeStatusException e) {\n        log.warn(e.getLocalizedMessage(), e);\n\n        return LocaleUtils\n            .resolveMessageReactive(\"error.unsupported_media_type\")\n            .map(msg -> ResponseMessage\n                .error(415, \"unsupported_media_type\", msg)\n                .result(e.getSupportedMediaTypes()));\n    }\n\n    @ExceptionHandler\n    @ResponseStatus(HttpStatus.NOT_ACCEPTABLE)\n    public Mono<ResponseMessage<Object>> handleException(NotAcceptableStatusException e) {\n        log.warn(e.getLocalizedMessage(), e);\n\n        return LocaleUtils\n            .resolveMessageReactive(\"error.not_acceptable_media_type\")\n            .map(msg -> ResponseMessage\n                .error(406, \"not_acceptable_media_type\", msg)\n                .result(e.getSupportedMediaTypes()));\n    }\n\n    @ExceptionHandler\n    @ResponseStatus(HttpStatus.NOT_ACCEPTABLE)\n    public Mono<ResponseMessage<Object>> handleException(MethodNotAllowedException e) {\n        log.warn(e.getLocalizedMessage(), e);\n\n        return LocaleUtils\n            .resolveMessageReactive(\"error.method_not_allowed\")\n            .map(msg -> ResponseMessage\n                .error(406, \"method_not_allowed\", msg)\n                .result(e.getSupportedMethods()));","sourceCodeStart":229,"sourceCodeEnd":265,"githubUrl":"https://github.com/hs-web/hsweb-framework/blob/b2cfc85a57c70bf5b5cf6e7edae2d37102652ec8/hsweb-commons/hsweb-commons-crud/src/main/java/org/hswebframework/web/crud/web/CommonErrorControllerAdvice.java#L229-L265","documentation":"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.","triggerScenarios":"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.","commonSituations":"API clients copy-pasted from different services with mismatched Accept headers; browser prefetch sending odd Accept values; gateways adding Accept headers.","solutions":["Change the Accept header to a type the server supports (listed in the 406 response result, typically application/json).","Use Accept: */* if any supported representation is acceptable.","If another format is genuinely required, add a message writer/encoder (e.g. Jackson XML) for it on the server.","Check intermediaries that inject or rewrite Accept headers."],"exampleFix":"// before\nAccept: application/vnd.vendor+xml\n// after\nAccept: application/json","handlingStrategy":"validation","validationCode":"const accept = 'application/json';\nif (accept !== 'application/json' && accept !== '*/*') {\n  console.warn(`Accept header ${accept} likely unsupported; use application/json`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  return await axios.get(url, { headers: { Accept: 'application/json' } });\n} catch (e) {\n  if (e.response && e.response.status === 406) {\n    return axios.get(url, { headers: { Accept: '*/*' } }); // fallback\n  }\n  throw e;\n}","preventionTips":["Default Accept to application/json or */*.","Inspect the supported media types returned in the 406 body.","Register writers for any format the API promises (e.g. XML).","Re-check content negotiation after Spring upgrades."],"tags":["http-406","content-negotiation","webflux","spring"],"backgroundTag":"not-acceptable-media-type","analyzedSha":"b2cfc85a57c70bf5b5cf6e7edae2d37102652ec8","analyzedAt":"2026-09-13T09:05:02.172Z","contentChangedAt":"2026-09-13T09:05:02.172Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}