Improving error handling
This commit is contained in:
1 parent
fbcd2099d5
commit
78e301f541
2 files changed
+50
-46
No files matched your search
@@ -17,42 +17,48 @@ const resolve = async (parent, { id }, context) => {
|
||||
if (!context.userId) {
|
||||
throw new AuthentificationError()
|
||||
}
|
||||
try {
|
||||
let clone = await Clone.findOne({
|
||||
_id: id,
|
||||
authId: context.userId,
|
||||
active: true
|
||||
})
|
||||
|
||||
let clone = await Clone.findOne({
|
||||
_id: id,
|
||||
authId: context.userId,
|
||||
active: true
|
||||
})
|
||||
|
||||
if (!isDefined(clone)) {
|
||||
throw new OperationsError('You are not authorized to remove this clone.')
|
||||
}
|
||||
|
||||
let team = await teamQuery(context.authorization, clone.teamId)
|
||||
clone = await cloneDetails(context.userId, team.data.data.teams_TeamById, clone)
|
||||
|
||||
logger.debug('removeClone -> Release the clone key.')
|
||||
await authorizeClone(context.authorization, clone.keyId, clone.id, true)
|
||||
|
||||
logger.debug('removeClone -> Removing Clone from Kubernates.')
|
||||
await removeKuberneteClone(clone)
|
||||
|
||||
const query = {
|
||||
_id: id,
|
||||
authId: context.userId
|
||||
}
|
||||
const options = { new: true }
|
||||
const update = { active: false }
|
||||
|
||||
Clone.findOneAndUpdate(query, update, options, (err, doc) => {
|
||||
if (err) {
|
||||
logger.error('removeClone -> Error removing clone from the DB. %s', err.stack)
|
||||
throw new OperationsError(err)
|
||||
} else {
|
||||
logger.debug('removeClone -> Clone Removed from the DB.')
|
||||
return ('Clone Removed.')
|
||||
if (!isDefined(clone)) {
|
||||
throw new OperationsError('You are not authorized to remove this clone.')
|
||||
}
|
||||
})
|
||||
|
||||
let team = await teamQuery(context.authorization, clone.teamId)
|
||||
clone = await cloneDetails(context.userId, team.data.data.teams_TeamById, clone)
|
||||
|
||||
logger.debug('removeClone -> Release the clone key.')
|
||||
await authorizeClone(context.authorization, clone.keyId, clone.id, true)
|
||||
|
||||
logger.debug('removeClone -> Removing Clone from Kubernates.')
|
||||
await removeKuberneteClone(clone)
|
||||
|
||||
const query = {
|
||||
_id: id,
|
||||
authId: context.userId
|
||||
}
|
||||
const options = { new: true }
|
||||
const update = { active: false }
|
||||
|
||||
return new Promise((res, rej) => {
|
||||
Clone.findOneAndUpdate(query, update, options, (err, doc) => {
|
||||
if (err) {
|
||||
logger.error('removeClone -> Error removing clone from the DB. %s', err.stack)
|
||||
rej(err)
|
||||
return
|
||||
}
|
||||
logger.debug('removeClone -> Clone Removed from the DB.')
|
||||
res('Clone Removed.')
|
||||
})
|
||||
})
|
||||
} catch (error) {
|
||||
logger.error('Error removing the clone. %s', error.stack)
|
||||
throw new OperationsError(error.message)
|
||||
}
|
||||
}
|
||||
|
||||
const RemoveCloneMutation = {
|
||||
|
||||
@@ -35,8 +35,6 @@ const resolve = async (parent,
|
||||
}
|
||||
|
||||
try {
|
||||
let sucessful
|
||||
|
||||
let clone = await Clone.findOne({
|
||||
_id: id,
|
||||
active: true
|
||||
@@ -63,19 +61,19 @@ const resolve = async (parent,
|
||||
}
|
||||
|
||||
logger.debug('UpdateExecutionSummary -> Updating clone on database.')
|
||||
await Clone.update(query, update, options, (err, clone) => {
|
||||
if (err) {
|
||||
logger.error('Error updating execution summary on the database. %s', err.stack)
|
||||
throw err
|
||||
} else {
|
||||
|
||||
return new Promise((res, rej) => {
|
||||
Clone.update(query, update, options, (err, clone) => {
|
||||
if (err) {
|
||||
logger.error('Error updating execution summary on the database. %s', err.stack)
|
||||
rej(err)
|
||||
return
|
||||
}
|
||||
logger.debug('Execution summary updated.')
|
||||
sucessful = true
|
||||
}
|
||||
res('Execution summary updated.')
|
||||
})
|
||||
})
|
||||
|
||||
if (sucessful) {
|
||||
return 'Execution summary updated.'
|
||||
}
|
||||
} catch (error) {
|
||||
logger.error('Error updating the execution summary. %s', error.stack)
|
||||
throw new OperationsError(error.message)
|
||||
|
||||
Reference in new issue
Block a user