How to use the http-status.INTERNAL_SERVER_ERROR function in http-status

To help you get started, we’ve selected a few http-status examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bookbrainz / bookbrainz-site / src / server / routes / auth.js View on Github external
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;
}
github IBM / taxinomitis / src / lib / training / numbers.ts View on Github external
//  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,
                };
github jakeliny / crush-management / server / modules / crush / routes.ts View on Github external
.catch((err) => {
        console.error('Erro: ' + err);
        sendResponse(res, httpStatus.INTERNAL_SERVER_ERROR, {});
      });
  }
github raphaellima8 / typescript-api / server / config / dbErrorHandler.ts View on Github external
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}`
  });
}
github Christilut / node-modern-boilerplate / server / helpers / error.ts View on Github external
  constructor(message: string, status: number = httpStatus.INTERNAL_SERVER_ERROR, isPublic: boolean = false) {
    super(message, status, isPublic, true)
  }
}
github anandundavia / express-api-structure / src / api / middlewares / error.js View on Github external
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;
github Christilut / node-modern-boilerplate / server / helpers / s3.ts View on Github external
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')
}
github coinolio / coinolio / core / server / src / utils / errors.js View on Github external
constructor(
    message,
    status = httpStatus.INTERNAL_SERVER_ERROR,
    isPublic = false
  ) {
    super(message, status, isPublic);
  }
}
github IBM / taxinomitis / src / lib / restapi / users.ts View on Github external
.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);
    }
}
github hagopj13 / node-express-mongoose-boilerplate / src / middlewares / error.js View on Github external
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);
};