mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-06-01 05:11:34 +02:00
Merge pull request #2985 from overleaf/msm-oerror-remove-unprocessable-entity-error
Replace UnprocessableEntityError with calls to unprocessableEntity() handler GitOrigin-RevId: 4bba389c8cdf87a40137d49db571fa81aaac4239
This commit is contained in:
@@ -12,6 +12,7 @@ const PrivilegeLevels = require('../Authorization/PrivilegeLevels')
|
||||
const TokenAccessHandler = require('../TokenAccess/TokenAccessHandler')
|
||||
const AuthenticationController = require('../Authentication/AuthenticationController')
|
||||
const Errors = require('../Errors/Errors')
|
||||
const HttpErrorHandler = require('../Errors/HttpErrorHandler')
|
||||
const ProjectEntityUpdateHandler = require('../Project/ProjectEntityUpdateHandler')
|
||||
const { expressify } = require('../../util/promises')
|
||||
|
||||
@@ -272,11 +273,11 @@ async function convertDocToFile(req, res, next) {
|
||||
info: { public: { message: 'Document not found' } }
|
||||
})
|
||||
} else if (err instanceof Errors.DocHasRangesError) {
|
||||
throw new HttpErrors.UnprocessableEntityError({
|
||||
info: {
|
||||
public: { message: 'Document has comments or tracked changes' }
|
||||
}
|
||||
})
|
||||
return HttpErrorHandler.unprocessableEntity(
|
||||
req,
|
||||
res,
|
||||
'Document has comments or tracked changes'
|
||||
)
|
||||
} else {
|
||||
throw err
|
||||
}
|
||||
|
||||
@@ -1,5 +1,16 @@
|
||||
const logger = require('logger-sharelatex')
|
||||
|
||||
function renderJSONError(res, message, info) {
|
||||
const fullInfo = { message, ...info }
|
||||
if (info.message) {
|
||||
logger.warn(
|
||||
info,
|
||||
`http error info shouldn't contain a 'message' field, will be overridden`
|
||||
)
|
||||
}
|
||||
res.json(fullInfo)
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
forbidden(req, res, message = 'restricted', info = {}) {
|
||||
res.status(403)
|
||||
@@ -7,16 +18,24 @@ module.exports = {
|
||||
case 'html':
|
||||
return res.render('user/restricted', { title: 'restricted' })
|
||||
case 'json':
|
||||
const fullInfo = { message, ...info }
|
||||
if (info.message) {
|
||||
logger.warn(
|
||||
info,
|
||||
`http error info shouldn't contain a 'message' field, will be overridden`
|
||||
)
|
||||
}
|
||||
return res.json(fullInfo)
|
||||
return renderJSONError(res, message, info)
|
||||
default:
|
||||
return res.send('restricted')
|
||||
}
|
||||
},
|
||||
|
||||
unprocessableEntity(req, res, message = 'unprocessable entity', info = {}) {
|
||||
res.status(422)
|
||||
switch (req.accepts(['html', 'json'])) {
|
||||
case 'html':
|
||||
return res.render('general/400', {
|
||||
title: 'Client Error',
|
||||
message: message
|
||||
})
|
||||
case 'json':
|
||||
return renderJSONError(res, message, info)
|
||||
default:
|
||||
return res.send('unprocessable entity')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,9 @@ const planFeatures = require('./planFeatures')
|
||||
const GroupPlansData = require('./GroupPlansData')
|
||||
const V1SubscriptionManager = require('./V1SubscriptionManager')
|
||||
const Errors = require('../Errors/Errors')
|
||||
const HttpErrorHandler = require('../Errors/HttpErrorHandler')
|
||||
const SubscriptionErrors = require('./Errors')
|
||||
const OError = require('@overleaf/o-error')
|
||||
const HttpErrors = require('@overleaf/o-error/http')
|
||||
|
||||
module.exports = SubscriptionController = {
|
||||
@@ -82,11 +84,7 @@ module.exports = SubscriptionController = {
|
||||
const user = AuthenticationController.getSessionUser(req)
|
||||
const plan = PlansLocator.findLocalPlanInSettings(req.query.planCode)
|
||||
if (!plan) {
|
||||
return next(
|
||||
new HttpErrors.UnprocessableEntityError({
|
||||
info: { public: { message: 'Plan not found' } }
|
||||
})
|
||||
)
|
||||
return HttpErrorHandler.unprocessableEntity(req, res, 'Plan not found')
|
||||
}
|
||||
return LimitationsManager.userHasV1OrV2Subscription(user, function(
|
||||
err,
|
||||
@@ -224,13 +222,16 @@ module.exports = SubscriptionController = {
|
||||
return res.sendStatus(201)
|
||||
}
|
||||
|
||||
if (err instanceof SubscriptionErrors.RecurlyTransactionError) {
|
||||
return next(
|
||||
new HttpErrors.UnprocessableEntityError({}).withCause(err)
|
||||
)
|
||||
} else if (err instanceof Errors.InvalidError) {
|
||||
return next(
|
||||
new HttpErrors.UnprocessableEntityError({}).withCause(err)
|
||||
if (
|
||||
err instanceof SubscriptionErrors.RecurlyTransactionError ||
|
||||
err instanceof Errors.InvalidError
|
||||
) {
|
||||
logger.warn(err)
|
||||
return HttpErrorHandler.unprocessableEntity(
|
||||
req,
|
||||
res,
|
||||
err.message,
|
||||
OError.getFullInfo(err).public
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ const UserSessionsManager = require('./UserSessionsManager')
|
||||
const UserUpdater = require('./UserUpdater')
|
||||
const SudoModeHandler = require('../SudoMode/SudoModeHandler')
|
||||
const Errors = require('../Errors/Errors')
|
||||
const HttpErrorHandler = require('../Errors/HttpErrorHandler')
|
||||
const OError = require('@overleaf/o-error')
|
||||
const HttpErrors = require('@overleaf/o-error/http')
|
||||
const EmailHandler = require('../Email/EmailHandler')
|
||||
@@ -108,10 +109,12 @@ const UserController = {
|
||||
errorData.info.public = {
|
||||
error: 'SubscriptionAdminDeletionError'
|
||||
}
|
||||
return next(
|
||||
new HttpErrors.UnprocessableEntityError(errorData).withCause(
|
||||
err
|
||||
)
|
||||
logger.warn(new OError(errorData).withCause(err))
|
||||
return HttpErrorHandler.unprocessableEntity(
|
||||
req,
|
||||
res,
|
||||
errorData.message,
|
||||
errorData.info.public
|
||||
)
|
||||
} else {
|
||||
return next(new OError(errorData).withCause(err))
|
||||
|
||||
Reference in New Issue
Block a user