{"record":{"id":"8e8ed7893117ef3d","repo":"hs-web/hsweb-framework","slug":"unsupported-media-type","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/CommonErrorControllerAdvice.java","lineNumber":235,"sourceCode":"\n        return LocaleUtils\n            .resolveThrowable(e, (err, msg) -> {\n                log.warn(msg, e);\n                return ResponseMessage.error(400, CodeConstants.Error.illegal_argument, msg);\n            });\n    }\n\n    @ExceptionHandler\n    @ResponseStatus(HttpStatus.BAD_REQUEST)\n    public Mono<ResponseMessage<Object>> handleException(AuthenticationException e) {\n        return LocaleUtils\n            .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()));","sourceCodeStart":217,"sourceCodeEnd":253,"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#L217-L253","documentation":"WebFlux's UnsupportedMediaTypeStatusException is translated to HTTP 415 with code unsupported_media_type, the localized 'error.unsupported_media_type' message, and the list of supported media types attached to the response result. It means the client sent a body with a Content-Type the endpoint cannot consume.","triggerScenarios":"POST/PUT with Content-Type like text/plain or application/x-www-form-urlencoded to an endpoint that decodes @RequestBody as JSON/other; missing Content-Type header where none can be inferred; Accept on the client forcing an unsupported writer during encoding.","commonSituations":"Older HTTP clients or curl defaults (application/x-www-form-urlencoded) posting JSON; misconfigured gateway rewriting Content-Type; API consumers ignoring the documented media type.","solutions":["Set the request Content-Type header to a type the endpoint supports (see supportedMediaTypes in the response body).","If sending JSON, use application/json and serialize the body correctly.","If the endpoint should accept another type, register a HttpMessageReader/decoder for that media type in the server codec configuration.","Check proxies/gateways for headers stripped or rewritten."],"exampleFix":"// before\nfetch('/api/user', {method:'POST', body: JSON.stringify(u)}) // no Content-Type\n// after\nfetch('/api/user', {method:'POST', headers:{'Content-Type':'application/json'}, body: JSON.stringify(u)})","handlingStrategy":"validation","validationCode":"const SUPPORTED = ['application/json'];\nif (!SUPPORTED.includes(headers['Content-Type'])) {\n  throw new Error(`Unsupported Content-Type: ${headers['Content-Type']}; use application/json`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  return await client.post(url, body, { headers: { 'Content-Type': 'application/json' } });\n} catch (e) {\n  if (e.response && e.response.status === 415) {\n    console.warn('415: use one of', e.response.data.result);\n  }\n  throw e;\n}","preventionTips":["Always set Content-Type explicitly in HTTP clients.","Read the supportedMediaTypes from the 415 response before retrying.","Keep server codec configuration in sync with documented media types.","Test clients against real endpoints with contract tests."],"tags":["http-415","content-type","webflux","spring"],"backgroundTag":"unsupported-media-type","analyzedSha":"b2cfc85a57c70bf5b5cf6e7edae2d37102652ec8","analyzedAt":"2026-09-13T09:05:02.172Z","contentChangedAt":"2026-09-13T09:05:02.172Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}