收藏
回答

WAServiceMainContext.js报错是什么引起的?

Error: MiniProgramError

{"1771300":{"success":true,"data":{"type":"game","name":"天国:拯救2","steam_appid":1771300,"required_age":0,"is_free":false,"controller_support":"full","dlc":[3119920,3468550],"short_description":"走进 15 世纪的欧洲,体验丰富多彩的开放世界,畅玩这款精彩的叙事驱动型角色扮演游戏,开启究极中世纪冒险,扮演年轻的亨利,踏上一场史诗级的旅程。","header_image":"https://shared.akamai.steamstatic.com/store_item_assets/steam/apps/1771300/header.jpg?t=1738836316","capsule_image":"https://shared.akamai.steamstatic.com/store_item_assets/steam/apps/1771300/93e28946c46f09d761bbfab1e17e8c1c4a8323a0/capsule_231x87.jpg?t=1738836316","capsule_imagev5":"https://shared.akamai.steamstatic.com/store_item_assets/steam/apps/1771300/93e28946c46f09d761bbfab1e17e8c1c4a8323a0/capsule_184x69.jpg?t=1738836316","website":"https://www.kingdomcomerpg.com/","legal_notice":"© 2025 Warhorse Studios s.r.o. Published by Deep Silver. Deep Silver is a division of PLAION. Deep Silver and Plaion and their respective logos are trademarks of Plaion GmbH, Embracer Platz 1, 6604 Hoefen, Austria. Warhorse and Kingdom Come: Deliverance are registered trademarks of Warhorse Studios s.r.o. Portions of this software are included under license © 2019-2025 Crytek GmbH. All rights reserved. Crytek, Cryengine and their respective logos are trademarks of Crytek GmbH. All other trademarks, logos and copyrights are property of their respective owners. All rights reserved.","developers":["Warhorse Studios"],"publishers":["Deep Silver"],"price_overview":{"currency":"CNY","initial":22800,"final":22800,"discount_percent":0,"initial_formatted":"","final_formatted":"¥ 228.00"},"packages":[635513,1109733],"package_groups":[{"name":"default","title":"购买 天国:拯救2","description":"","selection_text":"选择一个购买选项","save_text":"","display_type":0,"is_recurring_subscription":"false","subs":[{"packageid":635513,"percent_savings_text":" ","percent_savings":0,"option_text":"Kingdom Come: Deliverance II - ¥ 228.00","option_description":"","can_get_free_license":"0","is_free_license":false,"price_in_cents_with_discount":22800},{"packageid":1109733,"percent_savings_text":" ","percent_savings":0,"option_text":"Kingdom Come: Deliverance II Gold Edition - ¥ 298.00","option_description":"","can_get_free_license":"0","is_free_license":false,"price_in_cents_with_discount":29800}]}],"platforms":{"windows":true,"mac":false,"linux":false},"metacritic":{"score":88,"url":"https://www.metacritic.com/game/pc/kingdom-come-deliverance-ii?ftag=MCD-06-10aaa1f"},"categories":[{"id":2,"description":"单人"},{"id":22,"description":"Steam 成就"},{"id":28,"description":"完全支持控制器"},{"id":29,"description":"Steam 集换式卡牌"},{"id":23,"description":"Steam 云"},{"id":62,"description":"家庭共享"}],"genres":[{"id":"1","description":"动作"},{"id":"25","description":"冒险"},{"id":"3","description":"角色扮演"}],"screenshots":[{"id":0,"path_thumbnail":"https://shared.akamai.steamstatic.com/store_item_assets/steam/apps/1771300/ss_935ddb59f90bc2c21c706132cb9b446fe7851c19.600x338.jpg?t=1738836316","path_full":"https://shared.akamai.steamstatic.com/store_item_assets/steam/apps/1771300/ss_935ddb59f90bc2c21c706132cb9b446fe7851c19.1920x1080.jpg?t=1738836316"},{"id":1,"path_thumbnail":"https://shared.akamai.steamstatic.com/store_item_assets/steam/apps/1771300/ss_709f3329562cd2cfe6db70bac908b3e72eaef83b.600x338.jpg?t=1738836316","path_full":"https://shared.akamai.steamstatic.com/store_item_assets/steam/apps/1771300/ss_709f3329562cd2cfe6db70bac908b3e72eaef83b.1920x1080.jpg?t=1738836316"},{"id":2,"path_thumbnail":"https://shared.akamai.steamstatic.com/store_item_assets/steam/apps/1771300/ss_bd668f4d12300c019fa3fa73108aa62929fbf862.600x338.jpg?t=1738836316","path_full":"https://shared.akamai.steamstatic.com/store_item_assets/steam/apps/1771300/ss_bd668f4d12300c019fa3fa73108aa62929fbf862.1920x1080.jpg?t=1738836316"},{"id":3,"path_thumbnail":"https://shared.akamai.steamstatic.com/store_item_assets/steam/apps/1771300/ss_5580d672302cdc5f8b7161dc94f266341e61a182.600x338.jpg?t=1738836316","path_full":"https://shared.akamai.steamstatic.com/store_item_assets/steam/apps/1771300/ss_5580d672302cdc5f8b7161dc94f266341e61a182.1920x1080.jpg?t=1738836316"},{"id":4,"path_thumbnail":"https://shared.akamai.steamstatic.com/store_item_assets/steam/apps/1771300/ss_27e006df1aef43380ae7db0d0b08538b26b49daa.600x338.jpg?t=1738836316","path_full":"https://shared.akamai.steamstatic.com/store_item_assets/steam/apps/1771300/ss_27e006df1aef43380ae7db0d0b08538b26b49daa.1920x1080.jpg?t=1738836316"},{"id":5,"path_thumbnail":"https://shared.akamai.steamstatic.com/store_item_assets/steam/apps/1771300/ss_e9a693d1027ec19c4fdbe5156abc80adac7039f8.600x338.jpg?t=1738836316","path_full":"https://shared.akamai.steamstatic.com/store_item_assets/steam/apps/1771300/ss_e9a693d1027ec19c4fdbe5156abc80adac7039f8.1920x1080.jpg?t=1738836316"},{"id":6,"path_thumbnail":"https://shared.akamai.steamstatic.com/store_item_assets/steam/apps/1771300/ss_293abf266a1847da65bb633b9e76e851715a4b58.600x338.jpg?t=1738836316","path_full":"https://shared.akamai.steamstaticWAServiceMainContext.js?t=wechat&s=1739356931398&v=3.7.7:1)

    at Function.thirdErrorReport (WAServiceMainContext.js?t=wechat&s=1739356931398&v=3.7.7:1)

    at Object.thirdErrorReport (WAServiceMainContext.js?t=wechat&s=1739356931398&v=3.7.7:1)

    at i (WASubContext.js?t=wechat&s=1739356931398&v=3.7.7:1)

    at Object.cb (WASubContext.js?t=wechat&s=1739356931398&v=3.7.7:1)

    at V._privEmit (WASubContext.js?t=wechat&s=1739356931398&v=3.7.7:1)

    at V.emit (WASubContext.js?t=wechat&s=1739356931398&v=3.7.7:1)

    at WASubContext.js?t=wechat&s=1739356931398&v=3.7.7:1

    at n (WASubContext.js?t=wechat&s=1739356931398&v=3.7.7:1)

    at Fe (WASubContext.js?t=wechat&s=1739356931398&v=3.7.7:1)(env: Windows,mp,1.06.2412050; lib: 3.7.7)

此为微信开发者工具Stable 1.06.2412050,调试基础库:3.77的conse.log控制台报错,目前是在使用uniapp开发微信小程序,自定义了一个request请求的拦截器。只要一请求这个接口就报错,其他接口都正常。问AI也回答不出来个所以然,不知道此问题是由哪里引发的。页面在访问的时候会toast出一个在拦截器中的报错,下为拦截器代码,烦请各位大佬提供帮助:

// utils/request.js
export function request(options) {
  const baseUrl = 'https://xxx/miniapp/wechat'// 统一的基础 URL
  
  // 获取 Token
  const token = uni.getStorageSync('token');
  
  // 判断 Token 是否存在,如果没有,则跳转到登录页面
  if (!token && !options.url.includes('/index.php?action=login')) {
    // 如果没有 Token 并且请求的 URL 不是登录接口,则跳转到登录页面
    uni.redirectTo({
      url: '/pages/login/index',
    });
    return Promise.reject('No token, redirecting to login...');
  }


  // 默认设置 POST 请求方式
  const defaultOptions = {
    url: baseUrl + options.url,  // 拼接基础 URL
    method: options.method || 'POST'// 如果 options.method 有值,使用它;否则默认 POST
    data: options.data || {},
    header: {
      ...options.header,
      'Authorization': token ? `Bearer ${token}` : ''// 在请求头中添加 Token,如果有的话
	  'Content-Type': 'application/x-www-form-urlencoded', // 添加 Content-Type 为 application/json
    },
  };


  return new Promise((resolve, reject) => {
    uni.request({
      ...defaultOptions,
      success: (response) => {
        if (response.statusCode === 200) {
          // 响应拦截器:统一处理响应数据
          if (response.data.code === 200) {
            resolve(response.data);  // 成功返回
          } else {
            uni.showToast({
              title: response.data.message || '您还未登录',
              icon: 'none',
            });
            reject(response.data);  // 返回错误
          }
        } else {
          uni.showToast({
            title: `服务器错误 ${response.statusCode}`,
            icon: 'none',
          });
          reject(response);  // 服务器错误
        }
      },
      fail: (error) => {
        uni.showToast({
          title: '请求失败,请稍后再试',
          icon: 'none',
        });
        reject(error);  // 请求失败
      },
    });
  });
}


回答关注问题邀请回答
收藏

1 个回答

  • Confident
    Confident
    02-13

    没事了,问题找到了。原因是拦截器里只是判断了code码,而这个返回数据里没有code码,导致错误匹配,强制拦截并弹出报错导致的。打扰各位了!

    02-13
    有用
    回复
登录 后发表内容