From 44ae01170398214a071cc8ba5e7b1da4ab931a6e Mon Sep 17 00:00:00 2001 From: Brian Gough Date: Thu, 3 Aug 2017 15:56:59 +0100 Subject: [PATCH] added files out of sync error object --- services/clsi/app/coffee/CompileController.coffee | 3 ++- services/clsi/app/coffee/Errors.coffee | 7 +++++++ services/clsi/app/coffee/ResourceWriter.coffee | 3 ++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/services/clsi/app/coffee/CompileController.coffee b/services/clsi/app/coffee/CompileController.coffee index aefa70dd1b..6f93bfea74 100644 --- a/services/clsi/app/coffee/CompileController.coffee +++ b/services/clsi/app/coffee/CompileController.coffee @@ -4,6 +4,7 @@ Settings = require "settings-sharelatex" Metrics = require "./Metrics" ProjectPersistenceManager = require "./ProjectPersistenceManager" logger = require "logger-sharelatex" +Errors = require "./Errors" module.exports = CompileController = compile: (req, res, next = (error) ->) -> @@ -15,7 +16,7 @@ module.exports = CompileController = ProjectPersistenceManager.markProjectAsJustAccessed request.project_id, (error) -> return next(error) if error? CompileManager.doCompile request, (error, outputFiles = []) -> - if error?.message is "invalid state" + if error instanceOf Errors.FilesOutOfSyncError code = 409 # Http 409 Conflict status = "retry" else if error?.terminated diff --git a/services/clsi/app/coffee/Errors.coffee b/services/clsi/app/coffee/Errors.coffee index 4abea0bbbb..2e3ae7597d 100644 --- a/services/clsi/app/coffee/Errors.coffee +++ b/services/clsi/app/coffee/Errors.coffee @@ -5,6 +5,13 @@ NotFoundError = (message) -> return error NotFoundError.prototype.__proto__ = Error.prototype +FilesOutOfSyncError = (message) -> + error = new Error(message) + error.name = "FilesOutOfSyncError" + error.__proto__ = FilesOutOfSyncError.prototype + return error +FilesOutOfSyncError.prototype.__proto__ = Error.prototype module.exports = Errors = NotFoundError: NotFoundError + FilesOutOfSyncError: FilesOutOfSyncError diff --git a/services/clsi/app/coffee/ResourceWriter.coffee b/services/clsi/app/coffee/ResourceWriter.coffee index fca2c43682..725d069966 100644 --- a/services/clsi/app/coffee/ResourceWriter.coffee +++ b/services/clsi/app/coffee/ResourceWriter.coffee @@ -5,6 +5,7 @@ async = require "async" mkdirp = require "mkdirp" OutputFileFinder = require "./OutputFileFinder" Metrics = require "./Metrics" +Errors = require "./Errors" logger = require "logger-sharelatex" settings = require("settings-sharelatex") @@ -16,7 +17,7 @@ module.exports = ResourceWriter = if request.syncType? is "incremental" ResourceWriter.checkSyncState request.syncState, basePath, (error, ok) -> logger.log syncState: request.syncState, result:ok, "checked state on incremental request" - return callback new Error("invalid state") if not ok + return callback new Errors.FilesOutOfSyncError("invalid state for incremental update") if not ok ResourceWriter.saveIncrementalResourcesToDisk request.project_id, request.resources, basePath, callback else @saveAllResourcesToDisk request.project_id, request.resources, basePath, (error) ->