@@ -83,6 +83,15 @@ export default class MailtrapClient {
83
83
this . sandbox = sandbox ;
84
84
}
85
85
86
+ /**
87
+ * Validates that account ID is present, throws MailtrapError if missing.
88
+ */
89
+ private validateAccountIdPresence ( ) : void {
90
+ if ( ! this . accountId ) {
91
+ throw new MailtrapError ( ACCOUNT_ID_MISSING ) ;
92
+ }
93
+ }
94
+
86
95
/**
87
96
* Getter for Testing API. Warns if some of the required keys are missing.
88
97
*/
@@ -91,9 +100,7 @@ export default class MailtrapClient {
91
100
throw new MailtrapError ( TEST_INBOX_ID_MISSING ) ;
92
101
}
93
102
94
- if ( ! this . accountId ) {
95
- throw new MailtrapError ( ACCOUNT_ID_MISSING ) ;
96
- }
103
+ this . validateAccountIdPresence ( ) ;
97
104
98
105
return new TestingAPI ( this . axios , this . accountId ) ;
99
106
}
@@ -102,9 +109,7 @@ export default class MailtrapClient {
102
109
* Getter for General API.
103
110
*/
104
111
get general ( ) {
105
- if ( ! this . accountId ) {
106
- throw new MailtrapError ( ACCOUNT_ID_MISSING ) ;
107
- }
112
+ this . validateAccountIdPresence ( ) ;
108
113
109
114
return new GeneralAPI ( this . axios , this . accountId ) ;
110
115
}
@@ -113,9 +118,7 @@ export default class MailtrapClient {
113
118
* Getter for Contacts API.
114
119
*/
115
120
get contacts ( ) {
116
- if ( ! this . accountId ) {
117
- throw new MailtrapError ( ACCOUNT_ID_MISSING ) ;
118
- }
121
+ this . validateAccountIdPresence ( ) ;
119
122
120
123
return new ContactsBaseAPI ( this . axios , this . accountId ) ;
121
124
}
@@ -124,17 +127,13 @@ export default class MailtrapClient {
124
127
* Getter for Contact Lists API.
125
128
*/
126
129
get contactLists ( ) {
127
- if ( ! this . accountId ) {
128
- throw new MailtrapError ( ACCOUNT_ID_MISSING ) ;
129
- }
130
+ this . validateAccountIdPresence ( ) ;
130
131
131
132
return new ContactListsBaseAPI ( this . axios , this . accountId ) ;
132
133
}
133
134
134
135
get templates ( ) {
135
- if ( ! this . accountId ) {
136
- throw new MailtrapError ( ACCOUNT_ID_MISSING ) ;
137
- }
136
+ this . validateAccountIdPresence ( ) ;
138
137
139
138
return new TemplatesBaseAPI ( this . axios , this . accountId ) ;
140
139
}
0 commit comments