@@ -23,6 +23,7 @@ import (
2323	"google.golang.org/grpc/codes" 
2424	"google.golang.org/grpc/status" 
2525
26+ 	"github.com/bucketeer-io/bucketeer/pkg/api/api" 
2627	"github.com/bucketeer-io/bucketeer/pkg/locale" 
2728	"github.com/bucketeer-io/bucketeer/pkg/log" 
2829	"github.com/bucketeer-io/bucketeer/pkg/notification/command" 
@@ -55,14 +56,7 @@ func (s *NotificationService) CreateAdminSubscription(
5556				zap .Any ("recipient" , req .Command .Recipient ),
5657			)... ,
5758		)
58- 		dt , err  :=  statusInternal .WithDetails (& errdetails.LocalizedMessage {
59- 			Locale :  localizer .GetLocale (),
60- 			Message : localizer .MustLocalize (locale .InternalServerError ),
61- 		})
62- 		if  err  !=  nil  {
63- 			return  nil , statusInternal .Err ()
64- 		}
65- 		return  nil , dt .Err ()
59+ 		return  nil , api .NewGRPCStatus (err ).Err ()
6660	}
6761	var  handler  command.Handler  =  command .NewEmptyAdminSubscriptionCommandHandler ()
6862	err  =  s .mysqlClient .RunInTransactionV2 (ctx , func (contextWithTx  context.Context , _  mysql.Transaction ) error  {
@@ -95,14 +89,7 @@ func (s *NotificationService) CreateAdminSubscription(
9589				zap .Error (err ),
9690			)... ,
9791		)
98- 		dt , err  :=  statusInternal .WithDetails (& errdetails.LocalizedMessage {
99- 			Locale :  localizer .GetLocale (),
100- 			Message : localizer .MustLocalize (locale .InternalServerError ),
101- 		})
102- 		if  err  !=  nil  {
103- 			return  nil , statusInternal .Err ()
104- 		}
105- 		return  nil , dt .Err ()
92+ 		return  nil , api .NewGRPCStatus (err ).Err ()
10693	}
10794	if  errs  :=  s .publishDomainEvents (ctx , handler .Events ()); len (errs ) >  0  {
10895		s .logger .Error (
@@ -111,14 +98,7 @@ func (s *NotificationService) CreateAdminSubscription(
11198				zap .Any ("errors" , errs ),
11299			)... ,
113100		)
114- 		dt , err  :=  statusInternal .WithDetails (& errdetails.LocalizedMessage {
115- 			Locale :  localizer .GetLocale (),
116- 			Message : localizer .MustLocalize (locale .InternalServerError ),
117- 		})
118- 		if  err  !=  nil  {
119- 			return  nil , statusInternal .Err ()
120- 		}
121- 		return  nil , dt .Err ()
101+ 		return  nil , api .NewGRPCStatus (err ).Err ()
122102	}
123103	return  & notificationproto.CreateAdminSubscriptionResponse {}, nil 
124104}
@@ -407,14 +387,7 @@ func (s *NotificationService) updateAdminSubscription(
407387				zap .String ("id" , id ),
408388			)... ,
409389		)
410- 		dt , err  :=  statusInternal .WithDetails (& errdetails.LocalizedMessage {
411- 			Locale :  localizer .GetLocale (),
412- 			Message : localizer .MustLocalize (locale .InternalServerError ),
413- 		})
414- 		if  err  !=  nil  {
415- 			return  statusInternal .Err ()
416- 		}
417- 		return  dt .Err ()
390+ 		return  api .NewGRPCStatus (err ).Err ()
418391	}
419392	if  errs  :=  s .publishDomainEvents (ctx , handler .Events ()); len (errs ) >  0  {
420393		s .logger .Error (
@@ -424,14 +397,7 @@ func (s *NotificationService) updateAdminSubscription(
424397				zap .String ("id" , id ),
425398			)... ,
426399		)
427- 		dt , err  :=  statusInternal .WithDetails (& errdetails.LocalizedMessage {
428- 			Locale :  localizer .GetLocale (),
429- 			Message : localizer .MustLocalize (locale .InternalServerError ),
430- 		})
431- 		if  err  !=  nil  {
432- 			return  statusInternal .Err ()
433- 		}
434- 		return  dt .Err ()
400+ 		return  api .NewGRPCStatus (err ).Err ()
435401	}
436402	return  nil 
437403}
@@ -484,14 +450,7 @@ func (s *NotificationService) DeleteAdminSubscription(
484450				zap .String ("id" , req .Id ),
485451			)... ,
486452		)
487- 		dt , err  :=  statusInternal .WithDetails (& errdetails.LocalizedMessage {
488- 			Locale :  localizer .GetLocale (),
489- 			Message : localizer .MustLocalize (locale .InternalServerError ),
490- 		})
491- 		if  err  !=  nil  {
492- 			return  nil , statusInternal .Err ()
493- 		}
494- 		return  nil , dt .Err ()
453+ 		return  nil , api .NewGRPCStatus (err ).Err ()
495454	}
496455	if  errs  :=  s .publishDomainEvents (ctx , handler .Events ()); len (errs ) >  0  {
497456		s .logger .Error (
@@ -501,14 +460,7 @@ func (s *NotificationService) DeleteAdminSubscription(
501460				zap .String ("id" , req .Id ),
502461			)... ,
503462		)
504- 		dt , err  :=  statusInternal .WithDetails (& errdetails.LocalizedMessage {
505- 			Locale :  localizer .GetLocale (),
506- 			Message : localizer .MustLocalize (locale .InternalServerError ),
507- 		})
508- 		if  err  !=  nil  {
509- 			return  nil , statusInternal .Err ()
510- 		}
511- 		return  nil , dt .Err ()
463+ 		return  nil , api .NewGRPCStatus (err ).Err ()
512464	}
513465	return  & notificationproto.DeleteAdminSubscriptionResponse {}, nil 
514466}
@@ -587,14 +539,7 @@ func (s *NotificationService) GetAdminSubscription(
587539				zap .String ("id" , req .Id ),
588540			)... ,
589541		)
590- 		dt , err  :=  statusInternal .WithDetails (& errdetails.LocalizedMessage {
591- 			Locale :  localizer .GetLocale (),
592- 			Message : localizer .MustLocalize (locale .InternalServerError ),
593- 		})
594- 		if  err  !=  nil  {
595- 			return  nil , statusInternal .Err ()
596- 		}
597- 		return  nil , dt .Err ()
542+ 		return  nil , api .NewGRPCStatus (err ).Err ()
598543	}
599544	return  & notificationproto.GetAdminSubscriptionResponse {Subscription : subscription .Subscription }, nil 
600545}
@@ -794,14 +739,7 @@ func (s *NotificationService) listAdminSubscriptionsMySQL(
794739				zap .Error (err ),
795740			)... ,
796741		)
797- 		dt , err  :=  statusInternal .WithDetails (& errdetails.LocalizedMessage {
798- 			Locale :  localizer .GetLocale (),
799- 			Message : localizer .MustLocalize (locale .InternalServerError ),
800- 		})
801- 		if  err  !=  nil  {
802- 			return  nil , "" , 0 , statusInternal .Err ()
803- 		}
804- 		return  nil , "" , 0 , dt .Err ()
742+ 		return  nil , "" , 0 , api .NewGRPCStatus (err ).Err ()
805743	}
806744	return  subscriptions , strconv .Itoa (nextCursor ), totalCount , nil 
807745}
0 commit comments