You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Apple Wallet Pass更新接口返回204时出现格式错误日志的解决咨询

Apple Wallet Pass更新接口返回204时的格式错误解决建议

问题场景

开发可更新的Apple Wallet Pass时,实现了根据passesUpdatedSince参数判断是否需要更新凭证的接口,代码如下:

app
  .route(
    "/pass/v1/devices/:deviceLibraryIdentifier/registrations/:passTypeIdentifier"
  )
  .get(async (req, res) => {
    const { deviceLibraryIdentifier, passTypeIdentifier } = req.params;
    const { passesUpdatedSince } = req.query;
    const lastUpdated = <get lastUpdated>;
    const updatedRequired = parseInt(passesUpdatedSince) < lastUpdated;

    if (!updatedRequired) {
      console.log("no updates");
      return res.status(204).send();
    }

    <get serialNumbers>

    return res
      .set({ "Content-Type": "application/json" })
      .status(200)
      .send({
        serialNumbers,
        lastUpdated
      });
  });

当无需更新返回204状态码时,收到持续的错误日志:

'[2022-07-19 18:07:32 +0800] Get serial #s task (for device<deviceID>, pass type <passID>, last updated 1658224105; with web service url <webServiceUrl>) encountered error: Server response was malformed (The data couldn’t be read because it isn’t in the correct format.)'

查阅文档未发现204需要返回数据,但错误会持续到删除凭证。

解决建议

  • 使用sendStatus(204)替代status(204).send():在Express框架中,res.send(204)可能默认添加Content-Type头或空白响应体,而res.sendStatus(204)会严格遵循HTTP 204规范,返回空响应体且不设置多余响应头。
  • 确保响应体完全为空:检查接口返回的响应是否包含空白字符、换行符等冗余内容,Apple Wallet对204响应的格式校验极为严格,任何多余内容都会被判定为格式错误。
  • 清除不必要的响应头:返回204时,确保手动设置的Content-Type等响应头被清除,避免Wallet服务尝试解析不存在的响应体。
  • 校验时间戳解析逻辑:用Number(passesUpdatedSince)替代parseInt转换时间戳,避免因字符串格式问题导致错误判断,减少不必要的204返回场景。

内容的提问来源于stack exchange,提问作者Jason Lee

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.26 05:27:18