How to use token_expired_error method in localstack

Best Python code snippet using localstack_python

graphql.py

Source:graphql.py Github

copy

Full Screen

1import sentry_sdk2from django.core.exceptions import ObjectDoesNotExist, PermissionDenied3from graphene_django.views import GraphQLView as BaseGraphQLView4from graphql_jwt.exceptions import PermissionDenied as JwtPermissionDenied5from common_utils.consts import (6 API_NOT_IMPLEMENTED_ERROR,7 GENERAL_ERROR,8 INVALID_EMAIL_FORMAT_ERROR,9 OBJECT_DOES_NOT_EXIST_ERROR,10 PERMISSION_DENIED_ERROR,11 PROFILE_API_ERROR,12 PROFILE_DOES_NOT_EXIST_ERROR,13 PROFILE_HAS_NO_PRIMARY_EMAIL_ERROR,14 PROFILE_MUST_HAVE_ONE_PRIMARY_EMAIL,15 TOKEN_EXPIRED_ERROR,16)17from common_utils.exceptions import (18 APINotImplementedError,19 CommonGraphQLError,20 InvalidEmailFormatError,21 ProfileAPIError,22 ProfileDoesNotExistError,23 ProfileHasNoPrimaryEmailError,24 ProfileMustHaveOnePrimaryEmail,25 TokenExpiredError,26)27from youths.consts import (28 APPROVER_EMAIL_CANNOT_BE_EMPTY_FOR_MINORS_ERROR,29 CANNOT_CREATE_YOUTH_PROFILE_IF_UNDER_13_YEARS_OLD_ERROR,30 CANNOT_RENEW_YOUTH_PROFILE_ERROR,31 CANNOT_SET_PHOTO_USAGE_PERMISSION_IF_UNDER_15_YEARS_ERROR,32)33from youths.exceptions import (34 ApproverEmailCannotBeEmptyForMinorsError,35 CannotCreateYouthProfileIfUnder13YearsOldError,36 CannotRenewYouthProfileError,37 CannotSetPhotoUsagePermissionIfUnder15YearsError,38)39error_codes_shared = {40 Exception: GENERAL_ERROR,41 ObjectDoesNotExist: OBJECT_DOES_NOT_EXIST_ERROR,42 TokenExpiredError: TOKEN_EXPIRED_ERROR,43 PermissionDenied: PERMISSION_DENIED_ERROR,44 JwtPermissionDenied: PERMISSION_DENIED_ERROR,45 APINotImplementedError: API_NOT_IMPLEMENTED_ERROR,46 InvalidEmailFormatError: INVALID_EMAIL_FORMAT_ERROR,47 ProfileAPIError: PROFILE_API_ERROR,48}49error_codes_profile = {50 ProfileDoesNotExistError: PROFILE_DOES_NOT_EXIST_ERROR,51 ProfileHasNoPrimaryEmailError: PROFILE_HAS_NO_PRIMARY_EMAIL_ERROR,52 ProfileMustHaveOnePrimaryEmail: PROFILE_MUST_HAVE_ONE_PRIMARY_EMAIL,53}54# TODO Register youth profile error codes from the youths app to keep this utility clean?55error_codes_youth_profile = {56 ApproverEmailCannotBeEmptyForMinorsError: APPROVER_EMAIL_CANNOT_BE_EMPTY_FOR_MINORS_ERROR,57 CannotCreateYouthProfileIfUnder13YearsOldError: CANNOT_CREATE_YOUTH_PROFILE_IF_UNDER_13_YEARS_OLD_ERROR,58 CannotRenewYouthProfileError: CANNOT_RENEW_YOUTH_PROFILE_ERROR,59 CannotSetPhotoUsagePermissionIfUnder15YearsError: CANNOT_SET_PHOTO_USAGE_PERMISSION_IF_UNDER_15_YEARS_ERROR,60}61sentry_ignored_errors = (62 ObjectDoesNotExist,63 JwtPermissionDenied,64 PermissionDenied,65)66error_codes = {**error_codes_shared, **error_codes_profile, **error_codes_youth_profile}67class SentryGraphQLView(BaseGraphQLView):68 def execute_graphql_request(self, request, data, query, *args, **kwargs):69 """Extract any exceptions and send some of them to Sentry"""70 result = super().execute_graphql_request(request, data, query, *args, **kwargs)71 # If 'invalid' is set, it's a bad request72 if result and result.errors and not result.invalid:73 errors = [74 e75 for e in result.errors76 if not (77 isinstance(getattr(e, "original_error", None), CommonGraphQLError)78 or isinstance(79 getattr(e, "original_error", None), sentry_ignored_errors80 )81 )82 ]83 if errors:84 self._capture_sentry_exceptions(result.errors, query)85 return result86 def _capture_sentry_exceptions(self, errors, query):87 with sentry_sdk.configure_scope() as scope:88 scope.set_extra("graphql_query", query)89 for error in errors:90 if hasattr(error, "original_error"):91 error = error.original_error92 sentry_sdk.capture_exception(error)93 @staticmethod94 def format_error(error):95 def get_error_code(exception):96 """Get the most specific error code for the exception via superclass"""97 for exception in exception.mro():98 try:99 return error_codes[exception]100 except KeyError:101 continue102 try:103 error_code = get_error_code(error.original_error.__class__)104 except AttributeError:105 error_code = GENERAL_ERROR106 formatted_error = super(SentryGraphQLView, SentryGraphQLView).format_error(107 error108 )109 if error_code and (110 isinstance(formatted_error, dict)111 and not (112 "extensions" in formatted_error113 and "code" in formatted_error["extensions"]114 )115 ):116 formatted_error["extensions"] = {"code": error_code}...

Full Screen

Full Screen

consts.py

Source:consts.py Github

copy

Full Screen

1# Common errors2API_NOT_IMPLEMENTED_ERROR = "API_NOT_IMPLEMENTED_ERROR"3GENERAL_ERROR = "GENERAL_ERROR"4INVALID_EMAIL_FORMAT_ERROR = "INVALID_EMAIL_FORMAT"5OBJECT_DOES_NOT_EXIST_ERROR = "OBJECT_DOES_NOT_EXIST_ERROR"6PERMISSION_DENIED_ERROR = "PERMISSION_DENIED_ERROR"7PROFILE_HAS_NO_PRIMARY_EMAIL_ERROR = "PROFILE_HAS_NO_PRIMARY_EMAIL_ERROR"8PROFILE_DOES_NOT_EXIST_ERROR = "PROFILE_DOES_NOT_EXIST_ERROR"9TOKEN_EXPIRED_ERROR = "TOKEN_EXPIRED_ERROR"10PROFILE_API_ERROR = "PROFILE_API_ERROR"11# Profile specific errors...

Full Screen

Full Screen

password_recovery_messages.py

Source:password_recovery_messages.py Github

copy

Full Screen

1#2# wayne_production copyright © 2021 - all rights reserved3# Created at: 03/01/214# By: mauromarini5# License: MIT6# Repository: https://github.com/marinimau/wayne_django_rest7# Credits: @marinimau (https://github.com/marinimau)8#9messages = {10 'no_token_error': 'no token for the given user',11 'invalid_token_error': 'invalid token',12 'token_expired_error': 'token expired',13 'update_not_allowed': 'no update for this model',14 'invalid_email_error': 'invalid email',15 'password_modified': 'password modified',16 '404_error': 'not found'...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful