- Signature REST API Guides
- Welcome
- Getting Started
- Error handling
- Examples
- Basic
- Advanced
- Manage
Error handling
iLovePDF allows users to catch errors from all API requests. These errors can be from the Start request, Authentication, Upload files, Create Signature and Manage Signatures. The following example shows how to catch all of these errors in a single error sample:
Examples using a library
x
try {
//Start the task
$signTask = new SignTask("project_public_key", "private_secret_key");
// We first upload the file that we are going to use
$file = $signTask->addFile('/path/to/file');
// Add signers and their elements;
$signatureElement = new ElementSignature();
// and get the task tool
$myTask = $ilovepdf->newTask('split');
// file var keeps info about server file id, name...
// it can be used latter to cancel file
$file = $myTask->addFile('/path/to/file/document.pdf');
// Create a signer
$signer = new Signer("name","signer@email.com");
// Assign the signer an element to be signed
$signer->addElements($file, $signatureElement);
$signTask->addReceiver($signer);
$signature = $signTask->execute()->result;
$signatureToken = $signature["token_requester"];
// Get the current status of the signature:
$signatureRequest->getSignatureStatus($signatureToken);
} catch (\Ilovepdf\Exceptions\StartException $e) {
echo "An error occured on start: " . $e->getMessage() . " ";
// Authentication errors
} catch (\Ilovepdf\Exceptions\AuthException $e) {
echo "An error occured on auth: " . $e->getMessage() . " ";
echo implode(', ', $e->getErrors());
// Uploading files errors
} catch (\Ilovepdf\Exceptions\UploadException $e) {
echo "An error occured on upload: " . $e->getMessage() . " ";
echo implode(', ', $e->getErrors());
// Processing files errors
} catch (\Exception $e) {
echo "An error occured: " . $e->getMessage();
}
xxxxxxxxxx
// Under construction
xxxxxxxxxx
begin
require "bundler/setup"
require 'ilovepdf'
# You can call task class directly
my_task = Ilovepdf::Tool::Signature.new(pub_key, priv_key)
# File object keeps information about its server_filename and the properties you can set
file = my_task.add_file '/path/to/file/sample.pdf'
signer = Ilovepdf::Signature::Receiver.new(:signer,'name','email@email.com')
signature_element = Ilovepdf::Signature::SignatureElement.new(file)
signer << signature_element
body = my_task.send_to_sign.body
rescue Ilovepdf::ApiError => e
# Let's check what went wrong with the API call:
puts e.http_response.body
end
xxxxxxxxxx
try {
// Start an API instance.
ilovepdf = new Ilovepdf("PUBLIC_KEY", "SECRET_KEY");
// Get tool.
myTask = ilovepdf.newTask('split');
// Add file from URL.
myTask.addFile('/path/to/file/document.pdf');
// Process files.
myTask.process({
ranges: '2-4,6-8',
});
// Download data in a local file.
const data = await myTask.download('path/to/download');
fs.writeFileSync('foldername/folder1/', data);
} catch (Error err) {
if (err instanceof AuthError) {
console.log('Error on auth!');
}
}