11import graphene
22from graphene_sqlalchemy import SQLAlchemyObjectType
3- from graphql import GraphQLError
43from sqlalchemy import exc , func
54
65from api .office .models import Office as OfficeModel
1615from helpers .pagination .paginate import Paginate , validate_page
1716from helpers .email .email import notification
1817from helpers .auth .user_details import get_user_from_db
18+ from api .bugsnag_error import return_error
1919
2020
2121class Office (SQLAlchemyObjectType ):
@@ -41,7 +41,7 @@ class Arguments:
4141 def mutate (self , info , ** kwargs ):
4242 location = Location .query .filter_by (id = kwargs ['location_id' ]).first ()
4343 if not location :
44- raise GraphQLError ("Location not found" )
44+ return_error . report_errors_bugsnag_and_graphQL ("Location not found" )
4545 admin_roles .verify_admin_location (location_id = kwargs ['location_id' ])
4646 office = OfficeModel (** kwargs )
4747 admin = get_user_from_db ()
@@ -50,15 +50,16 @@ def mutate(self, info, **kwargs):
5050 admin_name = username .split ("." )[0 ]
5151 payload = {
5252 'model' : OfficeModel , 'field' : 'name' , 'value' : kwargs ['name' ]
53- }
53+ }
5454 with SaveContextManager (
55- office , 'Office' , payload
55+ office , 'Office' , payload
5656 ):
5757 new_office = kwargs ['name' ]
5858 if not notification .send_email_notification (
5959 email , new_office , location .name , admin_name
6060 ):
61- raise GraphQLError ("Office created but Emails not Sent" )
61+ return_error .report_errors_bugsnag_and_graphQL (
62+ "Office created but Emails not Sent" )
6263 return CreateOffice (office = office )
6364
6465
@@ -79,7 +80,7 @@ def mutate(self, info, office_id, **kwargs):
7980 exact_office = result .filter (
8081 OfficeModel .id == office_id ).first () # noqa: E501
8182 if not exact_office :
82- raise GraphQLError ("Office not found" )
83+ return_error . report_errors_bugsnag_and_graphQL ("Office not found" )
8384
8485 admin_roles .create_rooms_update_delete_office (office_id )
8586 update_entity_fields (exact_office , state = "archived" , ** kwargs )
@@ -104,13 +105,13 @@ def mutate(self, info, office_id, **kwargs):
104105 result = get_office .filter (OfficeModel .state == "active" )
105106 exact_office = result .filter (OfficeModel .id == office_id ).first ()
106107 if not exact_office :
107- raise GraphQLError ("Office not found" )
108+ return_error . report_errors_bugsnag_and_graphQL ("Office not found" )
108109 admin_roles .create_rooms_update_delete_office (office_id )
109110 try :
110111 update_entity_fields (exact_office , ** kwargs )
111112 exact_office .save ()
112113 except exc .SQLAlchemyError :
113- raise GraphQLError ("Action Failed" )
114+ return_error . report_errors_bugsnag_and_graphQL ("Action Failed" )
114115
115116 return UpdateOffice (office = exact_office )
116117
@@ -134,7 +135,7 @@ def resolve_offices(self, info, **kwargs):
134135 func .lower (OfficeModel .name )).limit (
135136 per_page ).offset (page * per_page )
136137 if result .count () == 0 :
137- return GraphQLError ("No more offices" )
138+ return_error . report_errors_bugsnag_and_graphQL ("No more offices" )
138139 return result
139140
140141
@@ -166,7 +167,7 @@ def resolve_get_office_by_name(self, info, name):
166167 active_offices = query .filter (OfficeModel .state == "active" )
167168 check_office = active_offices .filter (OfficeModel .name == name ).first ()
168169 if not check_office :
169- raise GraphQLError ("Office Not found" )
170+ return_error . report_errors_bugsnag_and_graphQL ("Office Not found" )
170171 if name == "Epic tower" :
171172 exact_query = lagos_office_join_location (active_offices )
172173 result = exact_query .filter (OfficeModel .name == name )
0 commit comments