@@ -19,19 +19,20 @@ const checkForFlags = (err, isPrincipal) => {
1919 return false ;
2020 }
2121
22- let { error, error_description : description } = err ;
22+ const { error, error_description : description } = err ;
2323
2424 if ( error && typeof error === 'object' ) {
2525 let activationLink ;
2626 if ( / A P I h a s n o t b e e n u s e d / . test ( error . message ) && Array . isArray ( error . details ) ) {
27- for ( let detail of error . details ) {
27+ for ( const detail of error . details ) {
2828 if ( ! detail || ! Array . isArray ( detail . links ) ) {
2929 continue ;
3030 }
3131 activationLink = ( detail . links . find ( link => / G o o g l e d e v e l o p e r s c o n s o l e A P I a c t i v a t i o n / . test ( link . description ) && link . url ) || { } ) . url ;
3232 if ( activationLink ) {
3333 return {
34- message : 'Gmail API needs to be enabled before it can be used' ,
34+ message : 'Please enable the Gmail API in your Google Developer Console to use this feature.' ,
35+ code : 'GMAIL_API_NOT_ENABLED' ,
3536 url : activationLink
3637 } ;
3738 }
@@ -40,44 +41,54 @@ const checkForFlags = (err, isPrincipal) => {
4041
4142 if ( / i n s u f f i c i e n t a u t h e n t i c a t i o n s c o p e s / i. test ( error . message ) ) {
4243 return {
43- message : 'EmailEngine can’t process Gmail API requests because the configured OAuth2 permission scopes are insufficient'
44+ message :
45+ 'The current OAuth2 permission scopes are not sufficient to process Gmail API requests. Please update the scopes in your configuration.' ,
46+ code : 'INSUFFICIENT_AUTH_SCOPES'
4447 } ;
4548 }
4649
4750 if ( / I n v a l i d t o p i c N a m e d o e s n o t m a t c h / . test ( error . message ) ) {
4851 return {
49- message : 'Cloud Pub/Sub and Gmail API OAuth2 applications must be for the same project'
52+ message :
53+ 'There is a mismatch between your Cloud Pub/Sub configuration and the Gmail API OAuth2 application project. Please ensure both are associated with the same project.' ,
54+ code : 'PROJECT_MISMATCH'
5055 } ;
5156 }
5257 }
5358
5459 if ( error === 'invalid_client' && / T h e O A u t h c l i e n t w a s n o t f o u n d / i. test ( description ) ) {
5560 return {
56- message : 'OAuth Client ID for Google is invalid'
61+ message : 'The OAuth Client ID is invalid. Please verify that your Google integration is configured with the correct Client ID.' ,
62+ code : 'INVALID_CLIENT_ID'
5763 } ;
5864 }
5965
6066 if ( error === 'invalid_client' && / U n a u t h o r i z e d / i. test ( description ) ) {
6167 return {
62- message : 'OAuth Client Secret for Google is invalid'
68+ message : 'The OAuth Client Secret is incorrect. Please verify that you have provided the correct Client Secret for your Google integration.' ,
69+ code : 'INVALID_CLIENT_SECRET'
6370 } ;
6471 }
6572
6673 if ( error === 'unauthorized_client' && / C l i e n t i s u n a u t h o r i z e d t o r e t r i e v e a c c e s s t o k e n s / i. test ( description ) ) {
6774 return {
68- message : 'Verify OAuth2 scopes and domain-wide delegation setup for you project'
75+ message :
76+ 'The client is not authorized to retrieve access tokens. Check your OAuth2 scopes and ensure domain-wide delegation is set up correctly for your project.' ,
77+ code : 'UNAUTHORIZED_CLIENT'
6978 } ;
7079 }
7180
7281 if ( error === 'invalid_request' && / I n v a l i d p r i n c i p a l / i. test ( description ) ) {
7382 return {
74- message : 'OAuth Client Email for Google is invalid'
83+ message : 'The OAuth Client Email provided is invalid. Please review your Google integration settings and correct the email if needed.' ,
84+ code : 'INVALID_CLIENT_EMAIL'
7585 } ;
7686 }
7787
7888 if ( isPrincipal && error === 'invalid_grant' && / a c c o u n t n o t f o u n d / i. test ( description ) ) {
7989 return {
80- message : 'Invalid Service Client Email'
90+ message : 'The Service Client Email is invalid or unrecognized. Please verify that your service account credentials are correct.' ,
91+ code : 'INVALID_SERVICE_CLIENT_EMAIL'
8192 } ;
8293 }
8394
@@ -495,8 +506,11 @@ class GmailOauth {
495506 if ( flag ) {
496507 await this . setFlag ( flag ) ;
497508 err . tokenRequest . flag = flag ;
509+ if ( flag . code && ! err . code ) {
510+ err . code = flag . code ;
511+ }
498512 }
499- } catch ( err ) {
513+ } catch ( E ) {
500514 // ignore
501515 } finally {
502516 if ( this . logger ) {
0 commit comments