Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (!deleteAuthorizationGranted) {
// Return an error status code - not able to get authorization
return status.BAD_REQUEST;
}
// Try to delete the user
const deleteUserByMetaBrainzID =
orm.func.user.deleteUserByMetaBrainzID(orm.knex);
let success = false;
try {
success = await deleteUserByMetaBrainzID(metabrainzUserID);
}
catch (err) {
// Any kind of uncaught error here, give an ISE
return status.INTERNAL_SERVER_ERROR;
}
if (success) {
// If the user could be deleted, return a 200 response.
return status.OK;
}
// Otherwise, the user was not found, return a 404 response.
return status.NOT_FOUND;
}
// and then try the call again
const project = await store.getProject(projectid);
if (!project) {
throw new Error('Project not found');
}
const classifier = await trainClassifier(project);
if (classifier.status === 'Available') {
body = await request.post(url, req);
}
else {
log.error({ classifier, projectid }, 'Failed to create missing classifier for test');
throw new Error('Failed to create classifier');
}
}
else if (err.statusCode === httpStatus.INTERNAL_SERVER_ERROR &&
err.message.includes("Input contains NaN, infinity or a value too large for dtype('float32')"))
{
log.error({ err, data }, 'Value provided outside of valid range?');
throw err;
}
else {
throw err;
}
}
return Object.keys(body)
.map((key) => {
return {
class_name : key,
confidence : body[key],
classifierTimestamp,
};
.catch((err) => {
console.error('Erro: ' + err);
sendResponse(res, httpStatus.INTERNAL_SERVER_ERROR, {});
});
}
export function dbErrorHandler(res:Response, err:any) {
const id = hri.random();
console.error("Database error ocurred: ", id, err);
res.status(HTTPStatus.INTERNAL_SERVER_ERROR).json({
code: 'ERR-002',
message: `Creation of user failed, error code ${id}`
});
}
constructor(message: string, status: number = httpStatus.INTERNAL_SERVER_ERROR, isPublic: boolean = false) {
super(message, status, isPublic, true)
}
}
const handler = (err, req, res, next) => {
const response = {
code: err.status || httpStatus.INTERNAL_SERVER_ERROR,
message: err.message || httpStatus[err.status],
errors: err.errors,
stack: err.stack,
};
if (env !== 'development') {
delete response.stack;
}
res.status(response.code);
res.json(response);
res.end();
};
exports.handler = handler;
export async function downloadFileAsBase64(key: string, bucket: string): Promise {
const s3Params: IDownloadFileArgs = {
bucket,
key
}
const file = await downloadFile(s3Params)
if (!file) {
message('download as base64: key not found on s3', {
extra: {
s3Params
}
})
throw new APIError('lease not found on s3', httpStatus.INTERNAL_SERVER_ERROR)
}
return 'data:text/plain;base64,' + file.toString('base64')
}
constructor(
message,
status = httpStatus.INTERNAL_SERVER_ERROR,
isPublic = false
) {
super(message, status, isPublic);
}
}
.json({ error : 'Class already has maximum allowed number of students' });
}
try {
const newstudent = await auth0.createStudent(tenant, req.body.username);
return res.status(httpstatus.CREATED)
.json(newstudent);
}
catch (err) {
if (userAlreadyExists(err)) {
return res.status(httpstatus.CONFLICT).json({ error : 'There is already a student with that username' });
}
log.error({ err }, 'Failed to create student account');
let statusCode = httpstatus.INTERNAL_SERVER_ERROR;
let errObj = { error : 'Failed to create new account' };
if (err.response && err.response.body && err.response.body.statusCode) {
statusCode = err.response.body.statusCode;
}
if (err.error) {
errObj = err.error;
}
return res.status(statusCode).json(errObj);
}
}
const errorConverter = (err, req, res, next) => {
let error = err;
if (!(error instanceof AppError)) {
const statusCode = error.statusCode || httpStatus.INTERNAL_SERVER_ERROR;
const message = error.message || httpStatus[statusCode];
error = new AppError(statusCode, message, false);
}
next(error);
};