[WebApiManager] use a new CorruptedJoinProjectResponseError

This commit is contained in:
Jakob Ackermann 2020-08-20 12:14:02 +01:00
parent 68bc9d0d23
commit 02a2382264
2 changed files with 13 additions and 8 deletions

View file

@ -6,6 +6,12 @@ class CodedError extends OError {
}
}
class CorruptedJoinProjectResponseError extends OError {
constructor() {
super('no data returned from joinProject request')
}
}
class DataTooLargeToParseError extends OError {
constructor(data) {
super('data too large to parse', {
@ -47,6 +53,7 @@ class WebApiRequestFailedError extends OError {
module.exports = {
CodedError,
CorruptedJoinProjectResponseError,
DataTooLargeToParseError,
MissingSessionError,
NotAuthorizedError,

View file

@ -4,7 +4,11 @@
const request = require('request')
const settings = require('settings-sharelatex')
const logger = require('logger-sharelatex')
const { CodedError, WebApiRequestFailedError } = require('./Errors')
const {
CodedError,
CorruptedJoinProjectResponseError,
WebApiRequestFailedError
} = require('./Errors')
module.exports = {
joinProject(project_id, user, callback) {
@ -32,15 +36,9 @@ module.exports = {
if (error) {
return callback(error)
}
let err
if (response.statusCode >= 200 && response.statusCode < 300) {
if (!(data && data.project)) {
err = new Error('no data returned from joinProject request')
logger.error(
{ err, project_id, user_id },
'error accessing web api'
)
return callback(err)
return callback(new CorruptedJoinProjectResponseError())
}
callback(
null,