Repository: plotly/dash
File: dash/dash.py (Python)

Code before:
                # and skip the traceback up to that point
                # if the error didn't come from inside a callback, we won't
                # skip anything.
                tb = get_current_traceback()
                skip = 0
                for i, line in enumerate(tb.plaintext.splitlines()):
                    if "%% callback invoked %%" in line:
                        skip = int((i + 1) / 2)
                        break
                return get_current_traceback(skip=skip).render_full(), 500

        if debug and dev_tools.ui:

            def _before_request():
                flask.g.timing_information = {
                    "__dash_server": {"dur": time.time(), "desc": None}
                }

            def _after_request(response):
                timing_information = flask.g.get("timing_information", None)
                if timing_information is None:
                    return response

                timing_information_dash = timing_information.get("__dash_server", None)
                if timing_information_dash is not None:
                    dash_total = timing_information["__dash_server"]
                    dash_total["dur"] = round((time.time() - dash_total["dur"]) * 1000)

                for name, info in timing_information.items():

                    value = name
                    if info.get("desc") is not None:
                        value += ';desc="{}"'.format(info["desc"])

                    if info.get("dur") is not None:
                        value += ";dur={}".format(info["dur"])

                    response.headers.add("Server-Timing", value)

                return response

            self.server.before_request(_before_request)

            self.server.after_request(_after_request)

        if (
            debug
            and dev_tools.serve_dev_bundles
            and not self.scripts.config.serve_locally
        ):
            # Dev bundles only works locally.

Review comment (suggestion):
```suggestion
                dash_total = timing_information.get("__dash_server", None)
                if dash_total is not None:
```

Code after:
                # and skip the traceback up to that point
                # if the error didn't come from inside a callback, we won't
                # skip anything.
                tb = get_current_traceback()
                skip = 0
                for i, line in enumerate(tb.plaintext.splitlines()):
                    if "%% callback invoked %%" in line:
                        skip = int((i + 1) / 2)
                        break
                return get_current_traceback(skip=skip).render_full(), 500

        if debug and dev_tools.ui:

            def _before_request():
                flask.g.timing_information = {
                    "__dash_server": {"dur": time.time(), "desc": None}
                }

            def _after_request(response):
                timing_information = flask.g.get("timing_information", None)
                if timing_information is None:
                    return response

                dash_total = timing_information.get("__dash_server", None)
                if dash_total is not None:
                    dash_total["dur"] = round((time.time() - dash_total["dur"]) * 1000)

                for name, info in timing_information.items():

                    value = name
                    if info.get("desc") is not None:
                        value += ';desc="{}"'.format(info["desc"])

                    if info.get("dur") is not None:
                        value += ";dur={}".format(info["dur"])

                    response.headers.add("Server-Timing", value)

                return response

            self.server.before_request(_before_request)

            self.server.after_request(_after_request)

        if (
            debug
            and dev_tools.serve_dev_bundles
            and not self.scripts.config.serve_locally
        ):
            # Dev bundles only works locally.
            self.scripts.config.serve_locally = True