mirror of
https://github.com/danielsogl/awesome-cordova-plugins.git
synced 2025-04-21 01:06:25 +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 { instanceAvailability, checkAvailability, wrap, wrapInstance, overrideFunction } from './plugin';
|
||||||
import { getPlugin, getPromise } from './util';
|
import { getPlugin, getPromise } from './util';
|
||||||
import { Observable } from 'rxjs/Observable';
|
import { Observable } from 'rxjs/Observable';
|
||||||
|
import 'rxjs/observable/throw';
|
||||||
|
|
||||||
export interface PluginConfig {
|
export interface PluginConfig {
|
||||||
/**
|
/**
|
||||||
@ -145,15 +146,16 @@ export function CordovaCheck(opts: CordovaCheckOptions = {}) {
|
|||||||
return (pluginObj: Object, methodName: string, descriptor: TypedPropertyDescriptor<any>): TypedPropertyDescriptor<any> => {
|
return (pluginObj: Object, methodName: string, descriptor: TypedPropertyDescriptor<any>): TypedPropertyDescriptor<any> => {
|
||||||
return {
|
return {
|
||||||
value: function(...args: any[]): any {
|
value: function(...args: any[]): any {
|
||||||
if (checkAvailability(pluginObj) === true) {
|
const check = checkAvailability(pluginObj);
|
||||||
|
if (check === true) {
|
||||||
return descriptor.value.apply(this, args);
|
return descriptor.value.apply(this, args);
|
||||||
} else {
|
} else {
|
||||||
if (opts.sync) {
|
if (opts.sync) {
|
||||||
return;
|
return null;
|
||||||
} else if (opts.observable) {
|
} 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…
x
Reference in New Issue
Block a user