Show More
@@ -370,7 +370,8 b' def json_errors(method):' | |||||
370 | message = e.log_message |
|
370 | message = e.log_message | |
371 | self.log.warn(message) |
|
371 | self.log.warn(message) | |
372 | self.set_status(e.status_code) |
|
372 | self.set_status(e.status_code) | |
373 |
|
|
373 | reply = dict(message=message, reason=e.reason) | |
|
374 | self.finish(json.dumps(reply)) | |||
374 | except Exception: |
|
375 | except Exception: | |
375 | self.log.error("Unhandled error in API request", exc_info=True) |
|
376 | self.log.error("Unhandled error in API request", exc_info=True) | |
376 | status = 500 |
|
377 | status = 500 | |
@@ -378,7 +379,7 b' def json_errors(method):' | |||||
378 | t, value, tb = sys.exc_info() |
|
379 | t, value, tb = sys.exc_info() | |
379 | self.set_status(status) |
|
380 | self.set_status(status) | |
380 | tb_text = ''.join(traceback.format_exception(t, value, tb)) |
|
381 | tb_text = ''.join(traceback.format_exception(t, value, tb)) | |
381 | reply = dict(message=message, traceback=tb_text) |
|
382 | reply = dict(message=message, reason=None, traceback=tb_text) | |
382 | self.finish(json.dumps(reply)) |
|
383 | self.finish(json.dumps(reply)) | |
383 | else: |
|
384 | else: | |
384 | return result |
|
385 | return result |
@@ -282,7 +282,7 b' class FileContentsManager(ContentsManager):' | |||||
282 | model['content'] = bcontent.decode('utf8') |
|
282 | model['content'] = bcontent.decode('utf8') | |
283 | except UnicodeError as e: |
|
283 | except UnicodeError as e: | |
284 | if format == 'text': |
|
284 | if format == 'text': | |
285 | raise web.HTTPError(400, "%s is not UTF-8 encoded" % path) |
|
285 | raise web.HTTPError(400, "%s is not UTF-8 encoded" % path, reason='bad format') | |
286 | else: |
|
286 | else: | |
287 | model['format'] = 'text' |
|
287 | model['format'] = 'text' | |
288 |
|
288 | |||
@@ -345,14 +345,14 b' class FileContentsManager(ContentsManager):' | |||||
345 | if os.path.isdir(os_path): |
|
345 | if os.path.isdir(os_path): | |
346 | if type_ not in (None, 'directory'): |
|
346 | if type_ not in (None, 'directory'): | |
347 | raise web.HTTPError(400, |
|
347 | raise web.HTTPError(400, | |
348 | u'%s is a directory, not a %s' % (path, type_)) |
|
348 | u'%s is a directory, not a %s' % (path, type_), reason='bad type') | |
349 | model = self._dir_model(path, content=content) |
|
349 | model = self._dir_model(path, content=content) | |
350 | elif type_ == 'notebook' or (type_ is None and path.endswith('.ipynb')): |
|
350 | elif type_ == 'notebook' or (type_ is None and path.endswith('.ipynb')): | |
351 | model = self._notebook_model(path, content=content) |
|
351 | model = self._notebook_model(path, content=content) | |
352 | else: |
|
352 | else: | |
353 | if type_ == 'directory': |
|
353 | if type_ == 'directory': | |
354 | raise web.HTTPError(400, |
|
354 | raise web.HTTPError(400, | |
355 | u'%s is not a directory') |
|
355 | u'%s is not a directory', reason='bad type') | |
356 | model = self._file_model(path, content=content, format=format) |
|
356 | model = self._file_model(path, content=content, format=format) | |
357 | return model |
|
357 | return model | |
358 |
|
358 |
@@ -79,6 +79,14 b' function($,' | |||||
79 | that.events.trigger("file_loaded.Editor", model); |
|
79 | that.events.trigger("file_loaded.Editor", model); | |
80 | }, |
|
80 | }, | |
81 | function(error) { |
|
81 | function(error) { | |
|
82 | that.events.trigger("file_load_failed.Editor", error); | |||
|
83 | if (error.xhr.responseJSON.reason === 'bad format') { | |||
|
84 | window.location = utils.url_path_join( | |||
|
85 | that.base_url, | |||
|
86 | 'files', | |||
|
87 | that.file_path | |||
|
88 | ); | |||
|
89 | } | |||
82 | cm.setValue("Error! " + error.message + |
|
90 | cm.setValue("Error! " + error.message + | |
83 | "\nSaving disabled."); |
|
91 | "\nSaving disabled."); | |
84 | that.save_enabled = false; |
|
92 | that.save_enabled = false; |
@@ -73,7 +73,7 b' require([' | |||||
73 | page.show(); |
|
73 | page.show(); | |
74 |
|
74 | |||
75 | window.onbeforeunload = function () { |
|
75 | window.onbeforeunload = function () { | |
76 | if (!editor.codemirror.isClean(editor.generation)) { |
|
76 | if (editor.save_enabled && !editor.codemirror.isClean(editor.generation)) { | |
77 | return "Unsaved changes will be lost. Close anyway?"; |
|
77 | return "Unsaved changes will be lost. Close anyway?"; | |
78 | } |
|
78 | } | |
79 | }; |
|
79 | }; |
General Comments 0
You need to be logged in to leave comments.
Login now