{"record":{"id":"6ba1f3da4f9e5119","repo":"kataras/iris","slug":"unexpected-mime-type-received-s-current-implem","errorCode":null,"errorMessage":"unexpected mime type received: %s / current implementation can not handle the received (and accepted) mime type: %s","messagePattern":"unexpected mime type received: (.+?) / current implementation can not handle the received \\(and accepted\\) mime type: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"x/client/client.go","lineNumber":541,"sourceCode":"\t\tcase *string:\n\t\t\t*v = string(b)\n\t\tcase *[]byte:\n\t\t\t*v = b\n\t\tdefault:\n\t\t\treturn fmt.Errorf(\"plain text response should accept a *string or a *[]byte\")\n\t\t}\n\n\tdefault:\n\t\tacceptContentType := trimHeader(resp.Request.Header.Get(acceptKey))\n\t\tmsg := \"\"\n\t\tif acceptContentType == contentType {\n\t\t\t// Here we make a special case, if the content type\n\t\t\t// was explicitly set by the request but we cannot handle it.\n\t\t\tmsg = fmt.Sprintf(\"current implementation can not handle the received (and accepted) mime type: %s\", contentType)\n\t\t} else {\n\t\t\tmsg = fmt.Sprintf(\"unexpected mime type received: %s\", contentType)\n\t\t}\n\t\terr = errors.New(msg)\n\t}\n\n\treturn\n}\n\nfunc trimHeader(v string) string {\n\tfor i, char := range v {\n\t\tif char == ' ' || char == ';' {\n\t\t\treturn v[:i]\n\t\t}\n\t}\n\treturn v\n}\n","sourceCodeStart":523,"sourceCodeEnd":555,"githubUrl":"https://github.com/kataras/iris/blob/7bedaf55a0b64bbb2248a5845a2c60d81a30996a/x/client/client.go#L523-L555","documentation":"This error is raised by the HTTP client's BindResponse when the server replied with a Content-Type the client cannot bind to the target struct. If the caller explicitly requested an unsupported content type it appends 'current implementation can not handle the received (and accepted) mime type', otherwise 'unexpected mime type received'. It prevents silently zero-valued unmarshalling of unexpected payloads.","triggerScenarios":"client_req.ReadJSON/Bind-style calls when the response Content-Type is text/plain, HTML (error pages), XML, or any type the client has no decoder for; explicitly setting a ContentType on the request that the response body does not match.","commonSituations":"A reverse proxy or server returning an HTML 500 page with text/html content type while the client expects JSON; calling an endpoint that returns CSV/HTML instead of JSON; misconfigured Accept/ContentType headers.","solutions":["Make the server respond with the expected Content-Type (e.g. application/json) even on errors","Verify the requested URL/endpoint actually returns the expected format","Check and correct the request's ContentType/Accept headers before sending","Inspect the raw response body/status to see what the server actually sent"],"exampleFix":"// before\nreq, _ := client.NewRequest(ctx, \"GET\", url, nil)\nreq.ReadJSON(&data) // unexpected mime type: text/html\n// after\nresp, _ := client.Do(req)\nif !strings.HasPrefix(resp.Header.Get(\"Content-Type\"), \"application/json\") {\n    return fmt.Errorf(\"non-JSON response (%s): %s\", resp.Header.Get(\"Content-Type\"), string(body))\n}","handlingStrategy":"validation","validationCode":"ct := resp.Header.Get(\"Content-Type\")\nif !strings.HasPrefix(ct, \"application/json\") {\n    return fmt.Errorf(\"expected JSON, got %q\", ct)\n}","typeGuard":"func isBindMimeErr(err error) bool {\n    return err != nil && (strings.Contains(err.Error(), \"unexpected mime type received\") || strings.Contains(err.Error(), \"can not handle the received (and accepted) mime type\"))\n}","tryCatchPattern":"err := req.ReadJSON(&out)\nif err != nil && strings.Contains(err.Error(), \"mime type\") {\n    body, _ := io.ReadAll(resp.Body)\n    return fmt.Errorf(\"server sent non-JSON (%s): %s\", resp.Header.Get(\"Content-Type\"), body)\n}","preventionTips":["Set explicit Accept headers and verify them against the endpoint contract","Check response status code before binding; error pages are usually HTML","Agree on Content-Type in API docs and enforce it server-side"],"tags":["http-client","content-type","binding"],"backgroundTag":"unsupported-content-type","analyzedSha":"7bedaf55a0b64bbb2248a5845a2c60d81a30996a","analyzedAt":"2026-08-30T20:38:16.250Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}