#cp.result
Represents the result of an operation which may end in success
or failure
. If it is a success
, a value
is typically provided. If it is a failure
, a message
is typically provided.
Using this type allows for more structured checking when performing an operation which may fail in a number of ways, rather than just calling error
and crashing out. For example:
Of course, simply checking the result and throwing an error
is a common case, so you can achieve the same result like so:
If you want to perform other tasks, check for .failure
or .success
and perform the appropriate response.
#API Overview
Functions - API calls offered directly by the extension
Constructors - API calls which return an object, typically one that offers API methods
Methods - API calls which can only be made on an object returned by a constructor