Example usage for com.facebook.react.bridge Promise reject

List of usage examples for com.facebook.react.bridge Promise reject

Introduction

In this page you can find the example usage for com.facebook.react.bridge Promise reject.

Prototype

void reject(String code, String message, @NonNull WritableMap userInfo);

Source Link

Document

Report an error with a custom code, error message and userInfo, an error not caused by an exception.

Usage

From source file:com.amazonaws.reactnative.s3.AWSRNS3TransferUtility.java

License:Open Source License

@ReactMethod
public void download(final ReadableMap options, final Promise promise) {
    if (!options.hasKey(REQUESTID)) {
        throw new IllegalArgumentException("requestid is not supplied");
    }// w  w w.  j a v a2 s. c  o m
    final String requestID = options.getString(REQUESTID);
    final Map<String, Object> map = requestMap.get(requestID);
    if (map == null) {
        throw new IllegalArgumentException("requestid is invalid");
    }
    final TransferObserver observer;
    try {
        observer = transferUtility.download((String) map.get(BUCKET), (String) map.get(KEY),
                new File((String) map.get(PATH)));
    } catch (final AmazonServiceException e) {
        promise.reject(e.getErrorCode(), e.getErrorMessage(), e);
        return;
    } catch (final AmazonClientException e) {
        promise.reject("", e.getMessage(), e);
        return;
    }
    transferIDMap.put(observer.getId(), requestID);
    map.put(TRANSFERID, observer.getId());
    if ((Boolean) map.get(SUBSCRIBE)) {
        this.subscribe(observer);
    }
    promise.resolve("success");
}

From source file:com.amazonaws.reactnative.s3.AWSRNS3TransferUtility.java

License:Open Source License

@ReactMethod
public void upload(final ReadableMap options, final Promise promise) {
    if (!options.hasKey(REQUESTID)) {
        throw new IllegalArgumentException("requestid is not supplied");
    }//  www.  j  av a2 s.  c  o  m
    final String requestID = options.getString(REQUESTID);
    final Map<String, Object> map = requestMap.get(requestID);
    if (map == null) {
        throw new IllegalArgumentException("requestid is invalid");
    }
    final TransferObserver observer;
    try {
        observer = transferUtility.upload((String) map.get(BUCKET), (String) map.get(KEY),
                new File((String) map.get(PATH)));
    } catch (final AmazonServiceException e) {
        promise.reject(e.getErrorCode(), e.getErrorMessage(), e);
        return;
    } catch (final AmazonClientException e) {
        promise.reject("", e.getMessage(), e);
        return;
    }
    transferIDMap.put(observer.getId(), requestID);
    map.put(TRANSFERID, observer.getId());
    if ((Boolean) map.get(SUBSCRIBE)) {
        this.subscribe(observer);
    }
    promise.resolve("success");
}