zulip/zulip

channel: Handle 500s from the server more naturally

開放

#6,296 建立於 2017年8月28日

 (12 則留言) (0 個反應) (0 位負責人)Python (7,339 個分叉)batch import
area: apiarea: productionbughelp wanted

倉庫指標

星標
 (19,672 顆星)
PR 合併指標
 (平均合併 36天 6小時) (30 天內合併 110 個 PR)

描述

Right now, if the server 500s on a JSON request from a client in a way that doesn't return valid JSON, we get this sort of JS exception sent back to the server.

Message:
Unexpected token < in JSON at position 0

Stacktrace:
SyntaxError: Unexpected token < in JSON at position 0
    at JSON.parse (<anonymous>)

    at Object.a.xhr_error_message (static/min/app.f993cb5274ab.js:1331:372)
       = static/js/channel.js line 110 column 27

    at error (static/min/app.f993cb5274ab.js:2062:742)
       = static/js/reactions.js line 25 column 28

I think we should fix this in 2 ways;

  • Make it ~impossible for an invalid-JSON response to come back from channel.js (e.g. have a set of 500 error pages for API URLs that are in JSON format), and mostly not change this code. This probably involves changes to both our nginx configuration (for "unexpected errors" where Django isn't even running). And then there's a probably simpler piece of changing zerver/middleware.py to handle unexpected exceptions in JSON style API routes at the Django level.
  • Make channel.js catch this exception and provide a more clear error message for what's happening (perhaps including the invalid JSON it received) in the report, via blueslip.error or something.

貢獻者指南