{"record":{"id":"56c81ad67638ce1d","repo":"hs-web/hsweb-framework","slug":"unsupported-media-type-error","errorCode":"unsupported_media_type","errorMessage":"error.unsupported_media_type","messagePattern":"error\\.unsupported_media_type","errorType":"http","errorClass":"UnsupportedMediaTypeStatusException","httpStatus":415,"severity":"warning","filePath":"hsweb-commons/hsweb-commons-crud/src/main/java/org/hswebframework/web/crud/web/CommonWebMvcErrorControllerAdvice.java","lineNumber":206,"sourceCode":"        log.warn(e.getLocalizedMessage(), e);\n\n        return ResponseMessage.error(400, e.getCode(), resolveMessage(e));\n    }\n\n    @ExceptionHandler\n    @ResponseStatus(HttpStatus.UNSUPPORTED_MEDIA_TYPE)\n    public ResponseMessage<Object> handleException(UnsupportedMediaTypeStatusException e) {\n        log.warn(e.getLocalizedMessage(), e);\n\n        return ResponseMessage\n            .error(415, \"unsupported_media_type\", LocaleUtils.resolveMessage(\"error.unsupported_media_type\"))\n            .result(e.getSupportedMediaTypes());\n    }\n\n    @ExceptionHandler\n    @ResponseStatus(HttpStatus.NOT_ACCEPTABLE)\n    public ResponseMessage<Object> handleException(NotAcceptableStatusException e) {\n        log.warn(e.getLocalizedMessage(), e);\n\n        return ResponseMessage\n            .error(406, \"not_acceptable_media_type\", LocaleUtils\n                .resolveMessage(\"error.not_acceptable_media_type\"))\n            .result(e.getSupportedMediaTypes());\n    }\n\n    @ExceptionHandler\n    @ResponseStatus(HttpStatus.NOT_ACCEPTABLE)\n    public ResponseMessage<Object> handleException(MethodNotAllowedException e) {\n        log.warn(e.getLocalizedMessage(), e);\n\n        return ResponseMessage\n            .error(406, \"method_not_allowed\", LocaleUtils.resolveMessage(\"error.method_not_allowed\"))\n            .result(e.getSupportedMethods());\n    }\n\n","sourceCodeStart":188,"sourceCodeEnd":224,"githubUrl":"https://github.com/hs-web/hsweb-framework/blob/b2cfc85a57c70bf5b5cf6e7edae2d37102652ec8/hsweb-commons/hsweb-commons-crud/src/main/java/org/hswebframework/web/crud/web/CommonWebMvcErrorControllerAdvice.java#L188-L224","documentation":"In the WebMvc (servlet) advice, NotAcceptableStatusException is mapped to HTTP 406 with code not_acceptable_media_type and the localized 'error.not_acceptable_media_type' message; the supported media types are attached via result(e.getSupportedMediaTypes()). Same semantics as the WebFlux case: the client's Accept header cannot be satisfied.","triggerScenarios":"Sending an Accept header (e.g. application/xml, vendor types) that none of the registered HttpMessageConverters can produce for the endpoint's return type in a Spring MVC deployment.","commonSituations":"Clients expecting XML output when only Jackson JSON is on the classpath; overly specific Accept patterns; content negotiation config (favorPathExtension/suffix) changes after a Spring upgrade.","solutions":["Set Accept to a supported type (typically application/json) as listed in the 406 response result.","Use Accept: */* to accept whatever the server produces.","Add the needed HttpMessageConverter (e.g. MappingJackson2XmlHttpMessageConverter) if non-JSON output is required.","Review content-negotiation configuration after framework upgrades that removed path-extension negotiation."],"exampleFix":"// before\nrequests.get(url, headers={'Accept': 'application/xml'})\n// after\nrequests.get(url, headers={'Accept': 'application/json'})","handlingStrategy":"validation","validationCode":"const accept = 'application/json';\nif (!['application/json', '*/*'].includes(accept)) {\n  console.warn(`Accept ${accept} unsupported by this Spring MVC endpoint`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  return restTemplate.exchange(url, GET, entity, ResponseMessage.class);\n} catch (HttpStatusCodeException e) {\n  if (e.getStatusCode() == HttpStatus.NOT_ACCEPTABLE) {\n    // retry with Accept: */* or read supportedMediaTypes from the body\n  }\n  throw e;\n}","preventionTips":["Keep Accept headers minimal (application/json or */*).","Register all converters your API documents.","Avoid Accept headers that rely on path-extension negotiation removed in newer Spring.","Contract-test content negotiation for every endpoint."],"tags":["http-406","content-negotiation","spring-mvc","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"}