zulip/zulip

channel: Handle 500s from the server more naturally

Open

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

在 GitHub 查看
 (12 留言) (0 反應) (0 負責人)Python (19,672 star) (7,339 fork)batch import
area: apiarea: productionbughelp wanted

描述

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.

貢獻者指南