Skip to content

Commit

Permalink
fix(core): return errors from CordovaCheck decorators
Browse files Browse the repository at this point in the history
fixes comment mentioned in #1268
  • Loading branch information
ihadeed committed Mar 27, 2017
1 parent 9348415 commit fd0a2e9
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/@ionic-native/core/decorators.ts
Original file line number Diff line number Diff line change
@@ -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 {
/**
Expand Down Expand Up @@ -145,15 +146,16 @@ export function CordovaCheck(opts: CordovaCheckOptions = {}) {
return (pluginObj: Object, methodName: string, descriptor: TypedPropertyDescriptor<any>): TypedPropertyDescriptor<any> => {
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<any>(() => {});
return Observable.throw(new Error(check && check.error));
}
return getPromise(() => {});
return Promise.reject(check && check.error);
}
}
};
Expand Down

0 comments on commit fd0a2e9

Please sign in to comment.