overleaf/services/filestore/app/js/Errors.js

55 lines
1.4 KiB
JavaScript
Raw Normal View History

2019-12-18 05:01:59 -05:00
const OError = require('@overleaf/o-error')
// Error class for legacy errors so they inherit OError while staying
// backward-compatible (can be instantiated with string as argument instead
// of object)
class BackwardCompatibleError extends OError {
constructor(messageOrOptions) {
let options
if (typeof messageOrOptions === 'string') {
options = { message: messageOrOptions }
} else if (!messageOrOptions) {
options = {}
} else {
options = messageOrOptions
}
super(options)
}
}
class NotFoundError extends BackwardCompatibleError {}
class WriteError extends BackwardCompatibleError {}
class ReadError extends BackwardCompatibleError {}
class HealthCheckError extends BackwardCompatibleError {}
2019-12-18 05:01:59 -05:00
class ConversionsDisabledError extends BackwardCompatibleError {}
class ConversionError extends BackwardCompatibleError {}
class SettingsError extends BackwardCompatibleError {}
class TimeoutError extends BackwardCompatibleError {}
2019-12-18 05:01:59 -05:00
class FailedCommandError extends OError {
constructor(command, code, stdout, stderr) {
super({
message: 'command failed with error exit code',
info: {
command,
code
}
})
this.stdout = stdout
this.stderr = stderr
this.code = code
}
}
module.exports = {
NotFoundError,
FailedCommandError,
ConversionsDisabledError,
WriteError,
ReadError,
ConversionError,
HealthCheckError,
SettingsError,
TimeoutError
}