Show:

Promise

Summary

An object that represents a promise to be fulfilled, through which the programmer can register callbacks for when the promise is fulfilled successfully or for when an error occurrs. All asyncronous methods from the LacunaWebPKI class return an instance of this object.

For instance, the method listCertificates returns a promise which is fulfilled when the list of certificates is finally available. You could register a callback for when that happens, and another one for if an error occurs, in the following manner:

pki.listCertificates()
.success(function(certs) {
    // Every success callback receives a single argument. Its type (either string, array or object) and meaning depend on the method that returned the promise.
    $scope.certificates = certs;
})
.error(function (message, error, origin) {
    // Every error callback receives 3 arguments:
    // - message: a user-friendly message describing the error that occurred
    // - error: a detailed string containing as much information about the error as possible, for instance the stack trace. This is a good value to be logged, not to be shown to the user.
    // - origin: a string denoting where the error originated. This should also not be shown to the user, but rather logged for diagnostic purposes.
    alert('pki error from ' + origin + ': ' + message);
    if (window.console) {
        window.console.log('pki error', error);
    }
});

The success callback argument's type and meaning depend on the method that returns the promise. Please refer to each method's documentation for such information.

NOTICE: You should not instantiate this object directly.

Constructor

Promise

Syntax

Promise

()

Summary

Item Index

Methods

Methods

error

Syntax

error

(
  • callback
)
chainable

Summary

Registers a callback to be called if an error occurs during the operation. The error callback signature is always the same, and so are the meaning of each argument, which are described in the example below.

Parameters:

  • callback Function

    A function to be called if the an error occurs during the operation.

Examples

pki.listCertificates()
.success(onListCertificatesCompleted)
.error(function (message, error, origin) {
    // The error callback always receives 3 arguments:
    // - message: a user-friendly message describing the error that occurred
    // - error: a detailed string containing as much information about the error as possible, for instance the stack trace. This is a good value to be logged, not to be shown to the user.
    // - origin: a string denoting where the error originated. This should also not be shown to the user, but rather logged for diagnostic purposes.
    alert('pki error from ' + origin + ': ' + message);
    if (window.console) {
        window.console.log('pki error', error);
    }
});

success

Syntax

success

(
  • callback
)
chainable

Summary

Registers a callback to be called when the operation is completed successfully. The callback receives a single argument representing the operation's result.

The type of the argument (either string, array or object) and its meaning depend on the method that returns the promise. Please refer to each method's documentation for such information.

Parameters:

  • callback Function

    A function to be called once the promise is fulfilled, receiving a single argument representing the operation's result.

Examples

pki.listCertificates().success(function(certs) {
    $scope.certificates = certs;
});