mirror of
https://github.com/danielsogl/awesome-cordova-plugins.git
synced 2025-02-21 00:23:00 +08:00
fix(core): return errors from CordovaCheck decorators
fixes comment mentioned in #1268
This commit is contained in:
parent
9348415cf5
commit
fd0a2e9acd
@ -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<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);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user