Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const RouteWrapper = config => {
// if user routes have been defined, take those in preference to the defaults
const errorResponse = {
code: HTTPStatus.NOT_FOUND,
message: HTTPStatus[HTTPStatus.NOT_FOUND]
}
const routes = config.routes || defaultRoutes(config.components)
const ErrorComponent = () =>
RenderError({
config,
response: errorResponse
})
// loops over routes and return react-router components
return (
{routes.map(route => {
// cancel if component not defined in user config, joi will validate user routes for component/path keys
if (!route.component && !route.getComponent) {
route.component = null
}
// on 'route' event:
HTTPStatus.BAD_REQUEST,
`Failed to parse body of request: ${err.message}`
)
return
}
const onResponse = Server.onHandlerResponse.bind(null, response)
const metadata = { headers: request.headers, url: request.url }
if (this.config.enableAuthEndpoint && this.authPathRegExp.test(request.url)) {
this.httpEvents.onAuthMessage(request.body, metadata, onResponse)
} else if (this.postPathRegExp.test(request.url)) {
this.httpEvents.onPostMessage(request.body, metadata, onResponse)
} else {
Server.terminateResponse(response, HTTPStatus.NOT_FOUND, 'Endpoint not found.')
}
})
}
app.use((err, req, res, next) => {
if (err.status === 404) {
return otherHelper.sendResponse(res, httpStatus.NOT_FOUND, false, null, err, 'Route Not Found', null);
} else {
console.log('\x1b[41m', err);
AddErrorToLogs(req, res, next, err);
return otherHelper.sendResponse(res, httpStatus.INTERNAL_SERVER_ERROR, false, null, err, null, null);
}
});
export async function deleteClassifierFromBluemix(
credentials: TrainingObjects.BluemixCredentials,
classifierId: string,
): Promise
{
const req = await createBaseRequest(credentials);
try {
const url = credentials.url + '/v3/classifiers/' + encodeURIComponent(classifierId);
await request.delete(url, req);
}
catch (err) {
if (err.statusCode === httpStatus.NOT_FOUND) {
log.debug({ classifierId }, 'Attempted to delete non-existent classifier');
return;
}
throw err;
}
}
.catch ((err: any) => {
if (err.statusCode === httpstatus.NOT_FOUND || err.message === 'ETIMEDOUT') {
log.warn({ err, url }, 'Image could not be downloaded');
}
else if (err.statusCode === httpstatus.FORBIDDEN || err.statusCode === httpstatus.UNAUTHORIZED) {
log.warn({ err, url }, 'Image download was forbidden');
return resolve(new Error(safeGetHost(url) + ERRORS.DOWNLOAD_FORBIDDEN));
}
else {
log.error({ err, url }, 'Download fail (probe)');
}
resolve(new Error(ERRORS.DOWNLOAD_FAIL + url));
});
}
classifierId: string,
): Promise
{
const req = {
auth : {
user : credentials.username,
pass : credentials.password,
},
};
try {
await request.delete(credentials.url + '/v1/classifiers/' + classifierId,
req);
}
catch (err) {
if (err.statusCode === httpStatus.NOT_FOUND) {
log.debug({ classifierId }, 'Attempted to delete non-existent classifier');
return;
}
throw err;
}
}
.then((pipelineError) => {
if (pipelineError) {
return pipelineError;
}
const err = new APIError('No such pipelineError data exists!', httpStatus.NOT_FOUND);
return Promise.reject(err);
});
},
static get status() {
return status.NOT_FOUND;
}
switch (error.response.status) {
case status.UNPROCESSABLE_ENTITY:
return dispatch(
addValidationNotifications(error.response.data.story.errors)
);
case status.UNAUTHORIZED:
return dispatch(
addNotification(
Notification.createNotification({
type,
message: I18n.t('users.You are not authorized to perform this action')
})
)
);
case status.NOT_FOUND:
return dispatch(
addNotification(
Notification.createNotification({
type,
message: I18n.t('not_found')
})
)
);
default:
return dispatch(
addDefaultErrorNotification(Notification)
);
}
}
.then((comment) => {
if (comment) {
this.upadteDeletedContent(comment);
return comment;
}
const err = new APIError('No such comment exists!', httpStatus.NOT_FOUND);
return Promise.reject(err);
});
},