[links] Some error checking

This commit is contained in:
Chris Bianca 2018-03-23 13:26:20 +00:00
parent 7f90e485c8
commit b9dab3cb17
1 changed files with 10 additions and 8 deletions

View File

@ -44,11 +44,12 @@ export default class Links extends ModuleBase {
* @returns {Promise.<String>}
*/
createDynamicLink(link: DynamicLink): Promise<string> {
try {
return getNativeModule(this).createDynamicLink(link.build());
} catch (error) {
return Promise.reject(error);
if (!(link instanceof DynamicLink)) {
throw new Error(
`Links:createDynamicLink expects a 'DynamicLink' but got type ${typeof link}`
);
}
return getNativeModule(this).createDynamicLink(link.build());
}
/**
@ -60,11 +61,12 @@ export default class Links extends ModuleBase {
link: DynamicLink,
type?: 'SHORT' | 'UNGUESSABLE'
): Promise<String> {
try {
return getNativeModule(this).createShortDynamicLink(link.build(), type);
} catch (error) {
return Promise.reject(error);
if (!(link instanceof DynamicLink)) {
throw new Error(
`Links:createShortDynamicLink expects a 'DynamicLink' but got type ${typeof link}`
);
}
return getNativeModule(this).createShortDynamicLink(link.build(), type);
}
/**