Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error handling #990

Open
nizyumka opened this issue Nov 15, 2022 Discussed in #987 · 2 comments
Open

Error handling #990

nizyumka opened this issue Nov 15, 2022 Discussed in #987 · 2 comments

Comments

@nizyumka
Copy link

Discussed in #987

Originally posted by izumovn November 12, 2022
Error handling when telegram unavailable error and application crash when module is initialized?

Example app crashed
IMAGE 2022-11-12 23:59:32

@EnOane
Copy link

EnOane commented Mar 21, 2023

import { ExecutionContext, Injectable, Type } from '@nestjs/common';
import { Reflector } from '@nestjs/core';
import { AuthGuard } from '@nestjs/passport';
import { Observable } from 'rxjs';

import {
IS_PUBLIC_KEY,
JWT_GUARD,
} from '@/application/api/http-rest/authentication/constants';

@Injectable()
export class HttpJwtAuthGuard extends AuthGuard(JWT_GUARD) {
public constructor(private readonly reflector: Reflector = new Reflector()) {
super();
}

public canActivate(
context: ExecutionContext,
): boolean | Promise | Observable {
const contextType: string = context.getType();

if (contextType === 'telegraf') {
  return true;
}

const isPublic: boolean = this.reflector.getAllAndOverride<boolean>(
  IS_PUBLIC_KEY,
  [context.getHandler(), context.getClass()],
);

if (isPublic) {
  return true;
}

return super.canActivate(context);

}
}

@nizyumka
Copy link
Author

HttpJwtAuthGuard

It has to work inside the application, and the function is called from another service

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants