import logger from '../utils/logger';

const catchError = () => async (ctx, next) => {
  try {
    await next();
    const { url } = ctx;

    if (/^\/dashboard/g.test(url)) {
      logger.info(`[OLD URL REQUEST][${ctx.status}][${url}]`);
      const { githubLogin } = ctx.session;
      return await ctx.redirect(`/${githubLogin}`);
    }

    if (ctx.status === 404) {
      const login = url.split('/')[0];
      await ctx.redirect(`/${login}`);
    }
  } catch (err) {
    logger.error(err);
    ctx.redirect('/user/logout');
  }
}

export default catchError;

@@ -275,16 +275,101 @@
 ession;%0A
+      if (!githubLogin) %7B%0A        return await ctx.redirect('/user/logout');%0A      %7D%0A
       re

Handle 404 error