diff --git a/src/@ionic-native/core/decorators.ts b/src/@ionic-native/core/decorators.ts index 15a3717ac..00d665eb3 100644 --- a/src/@ionic-native/core/decorators.ts +++ b/src/@ionic-native/core/decorators.ts @@ -1,6 +1,7 @@ import { instanceAvailability, checkAvailability, wrap, wrapInstance, overrideFunction } from './plugin'; import { getPlugin, getPromise } from './util'; import { Observable } from 'rxjs/Observable'; +import 'rxjs/observable/throw'; export interface PluginConfig { /** @@ -145,15 +146,16 @@ export function CordovaCheck(opts: CordovaCheckOptions = {}) { return (pluginObj: Object, methodName: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor => { return { value: function(...args: any[]): any { - if (checkAvailability(pluginObj) === true) { + const check = checkAvailability(pluginObj); + if (check === true) { return descriptor.value.apply(this, args); } else { if (opts.sync) { - return; + return null; } else if (opts.observable) { - return new Observable(() => {}); + return Observable.throw(new Error(check && check.error)); } - return getPromise(() => {}); + return Promise.reject(check && check.error); } } };