首页 > 解决方案 > 内部服务器错误:没有找到适合响应类型的 HttpMessageConverter

问题描述

状态:500,错误:“内部服务器错误”消息:无法提取响应:找不到适合响应类型 [class com.clone.instagram.authservice.fetchdata.model.Example] 和内容类型 [text/html;charset] 的 HttpMessageConverter =utf-8]"

奇怪的是,这个错误在访问 insta API 时开始出现,奇怪的是这种情况“只是有时”发生,而且以前从未发生过。 它有时有效,有时会弹出此错误

const request = (options) => {
          const headers = new Headers();
        
          
            headers.append("Content-Type", "application/json");
          
        
          if (localStorage.getItem("accessToken")) {
            headers.append(
              "Authorization",
              "Bearer " + localStorage.getItem("accessToken")
            );
          }
        
          const defaults = { headers: headers };
          options = Object.assign({}, defaults, options);
        
          return fetch(options.url, options).then((response) =>
            response.json().then((json) => {
              if (!response.ok) {
                return Promise.reject(json);
              }
              return json;
            })
          );
        };
        
  export function registerInstaUserInfo(instaUserINfoRequest){
      if (!localStorage.getItem("accessToken")) {
        return Promise.reject("No access token set.");
      }
      
      console.log("inside getInstaUserInfo request ");
      return request({
        url: properties.INSTA_USER_REGISTER ,
        method: "POST",
        body: JSON.stringify(instaUserINfoRequest),
      });
    }
    
  const getInstaUserInfoFromService = (response) => {
        //store respose.data
        if (response.data.user_id) {
          console.log("setting up insta user staate ", response.data);
          localStorage.setItem("insta_user", response.data);
          cookies.set("insta_user", response.data, { path: "/" });
          console.log("cookies ", cookies.get("insta_user"));
          const fb_access_token = localStorage.getItem("accessToken");
          console.log("fb_access_token", fb_access_token);
          const user_info = registerInstaUserInfo(response.data)
            .then((res) => {
              console.log(res);
              setLinkedInstaAccounts([...linkedAccounts, res]);
            })
            .catch((err) => console.error("Hello stackoverlflowpeople this is where error happens", err));
    
          console.log("user_info", user_info);
          props.history.push("/home");
          //redirecting to account.js
          // props.history.push("/me");
        }
      };
    
  const successResponse = (code) => {
        console.log("inside success func");
        console.log(code);
        var bodyFormData = new FormData();
        bodyFormData.append("redirect_uri", properties.INSTA_REDIRECT_URL);
        bodyFormData.append("code", code);
        bodyFormData.append("client_id", properties.INSTA_CLIENT_ID);
        bodyFormData.append("client_secret", properties.INSTA_CLIENT_SECRECT);
        bodyFormData.append("grant_type", "authorization_code");
        axios({
          method: "post",
          url: properties.INSTA_ACCESS_TOKEN_URL,
          data: bodyFormData,
          headers: {
            "Content-Type": "multipart/form-data",
            Accept: "application/vnd.api+json",
          },
        })
          .then(getInstaUserInfoFromService)
          .catch(function (response) {
            //handle error
            console.log(response);
          });
      };
    
    
    ----
    //component
      <InstagramLogin
            clientId={properties.INSTA_CLIENT_ID}
            buttonText="Login"
            redirectUri={properties.INSTA_REDIRECT_URL}
            scope="user_profile,user_media"
            onSuccess={successResponse}
            onFailure={failedresponseInstagram}
          />

    

=====================这个 getInstaUserFromService 是发生错误的地方

const getInstaUserInfoFromService = (response) => {
        //store respose.data
        if (response.data.user_id) {
          console.log("setting up insta user staate ", response.data);
          localStorage.setItem("insta_user", response.data);
          cookies.set("insta_user", response.data, { path: "/" });
          console.log("cookies ", cookies.get("insta_user"));
          const fb_access_token = localStorage.getItem("accessToken");
          console.log("fb_access_token", fb_access_token);
          const user_info = registerInstaUserInfo(response.data)
            .then((res) => {
              console.log(res);
              setLinkedInstaAccounts([...linkedAccounts, res]);
            })
            .catch((err) => console.error("Hello stackoverlflowpeople this is where error happens", err));
    
          console.log("user_info", user_info);
          props.history.push("/home");
          //redirecting to account.js
          // props.history.push("/me");
        }
      };

我正在使用它,但我没有触及标题或任何东西,它与 Instagram 服务器有关吗?

标签: javascriptreactjswebheaderinstagram-api

解决方案


推荐阅读