Skip to content

Commit 315048a

Browse files
Improved error message of _checkParams to show correct method signature. Raised in arthurvasconcelos#6
1 parent b8e9c4d commit 315048a

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## NEXT ()
44

55
- [#23](https://github.com/arthurvasconcelos/vue-izitoast/issues/23) [BUGFIX] Fixed undefined toast in Vue prototype.
6+
- [#6](https://github.com/arthurvasconcelos/vue-izitoast/issues/6) [IMPROVEMENT] Improved error message of `_checkParams` to show correct method signature.
67

78
### Breaking Changes
89

src/vue-izitoast.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,19 @@ export function devMode() {
1212

1313
export default class VueIziToast {
1414
// Static Methods
15-
static _checkParams(message, title, options) {
15+
static _checkParams(message, title, options, methodName = null) {
16+
const methodSignature = (!methodName) ? '' : ` Method signature: ${methodName}(message: string, title: string, options: IzitoastOptions)`;
17+
1618
if (!message || message.constructor !== String) {
17-
throw 'Message must be a string';
19+
throw `Message must be a string.${methodSignature}`;
1820
}
21+
1922
if (title && title.constructor !== String) {
20-
throw 'Title must be a string';
23+
throw `Title must be a string.${methodSignature}`;
2124
}
25+
2226
if (options && options.constructor !== Object) {
23-
throw 'Options must be a object';
27+
throw `Options must be a object.${methodSignature}`;
2428
}
2529
}
2630

@@ -114,7 +118,7 @@ export default class VueIziToast {
114118
}
115119

116120
show(message, title = '', options = {}) {
117-
VueIziToast._checkParams(message, title, options);
121+
VueIziToast._checkParams(message, title, options, 'show');
118122
this._izi.show(Object.assign({}, options, { message, title }));
119123
}
120124

@@ -136,27 +140,27 @@ export default class VueIziToast {
136140
}
137141

138142
info(message, title = '', options = {}) {
139-
VueIziToast._checkParams(message, title, options);
143+
VueIziToast._checkParams(message, title, options, 'info');
140144
this._izi.info(Object.assign({}, options, { message, title }));
141145
}
142146

143147
success(message, title = '', options = {}) {
144-
VueIziToast._checkParams(message, title, options);
148+
VueIziToast._checkParams(message, title, options, 'success');
145149
this._izi.success(Object.assign({}, options, { message, title }));
146150
}
147151

148152
warning(message, title = '', options = {}) {
149-
VueIziToast._checkParams(message, title, options);
153+
VueIziToast._checkParams(message, title, options, 'warning');
150154
this._izi.warning(Object.assign({}, options, { message, title }));
151155
}
152156

153157
error(message, title = '', options = {}) {
154-
VueIziToast._checkParams(message, title, options);
158+
VueIziToast._checkParams(message, title, options, 'error');
155159
this._izi.error(Object.assign({}, options, { message, title }));
156160
}
157161

158162
question(message, title = '', options = {}) {
159-
VueIziToast._checkParams(message, title, options);
163+
VueIziToast._checkParams(message, title, options, 'question');
160164
this._izi.question(Object.assign({}, options, { message, title }));
161165
}
162166

0 commit comments

Comments
 (0)