Skip to main content
Question

Error Handling in React Embedded signing

  • 24 June 2024
  • 4 replies
  • 103 views

Hi Team,

  I’ m integrating docusign Embedded Signing in React js Application. 

  I create below component : 

import React, {useEffect} from 'react';
import PropTypes from 'prop-types';

function DocumentSignUI({integrationKey, docUrl}) {
useEffect(() => {
const loadDocuSign = async () => {

const docusign = await window.DocuSign.loadDocuSign(integrationKey);
const url = `${docUrl}&output=embed`;

const signing = docusign.signing({
url,
displayFormat: 'focused',
style: {

/** High-level variables that mirror our existing branding APIs. Reusing the branding name here for familiarity. */
branding: {
primaryButton: {
/** Background color of primary button */
backgroundColor: '#333',
/** Text color of primary button */
color: '#fff',
}
},

/** High-level components we allow specific overrides for */
signingNavigationButton: {
finishText: 'Custom Button Text',
/** 'bottom-left'|'bottom-center'|'bottom-right', default: bottom-right */
position: 'bottom-left'
}
}
});

signing.on('ready', (event) => {
console.log('ready event', event);
});

signing.on('sessionEnd', (event) => {
console.log('sessionend event', event);
if (event.sessionEndType === 'signing_complete') {
console.log('signing_complete', event);
}
});

signing.mount('#agreement');

};

console.log('DOCUSIGN RENDER');
loadDocuSign();
}, ]);

return (
<div className="docusign-agreement" id="agreement"/>
);
}

DocumentSignUI.propTypes = {
integrationKey: PropTypes.string.isRequired,
docUrl: PropTypes.string.isRequired,
};

export default DocumentSignUI;


It’s working fine if url is not expired.
But if url is expired then I’m not getting event in sessionEnd.
I also tried with try catch block but it’s not working.

If any type of error occured then I want to show error message try again.
Any body have idea, how to handle it ?
 

4 replies

Badge +1

Hi @Virendra Patidar

The following events can trigger the event handler (sessionEnd) which denote what caused the sessionEnd to trigger. You can use them  to show error message accordingly.

  •     signing_complete
  •     cancel
  •     decline
  •     exception
  •     fax_pending
  •     session_timeout
  •     ttl_expired
  •     viewing_complete

https://developers.docusign.com/docs/esign-rest-api/esign101/concepts/embedding/#docusign-js

 

Badge +1

We are not getting any event if below reason -

1. Presigned url expired2. Already used url3. Error in load docusign bundle script4. Any network issue in connectivity5. Wrong integration key or expired key6. Amy issue in mount docusign



How I integrated  in React js application -
 

/* istanbul ignore file */
// Unpublished Work © 2024 Deere & Company.

import React, {useEffect} from 'react';
import PropTypes from 'prop-types';
import './docu_sign.css';
import Script from 'react-load-script';
import {useState} from '@types/react';

const timeoutMs = 15000;
const docusignBundle = "https://js-d.docusign.com/bundle.js";

function DocuSignUi({integrationKey, docUrl}) {
console.log('docUrl', docUrl);

const [isScriptLoaded, setScriptLoaded] = useState(false);

const loadDocuSign = async () => {
const docusign = await window.DocuSign.loadDocuSign(integrationKey);
const url = `${docUrl}&output=embed`;

const signing = docusign.signing({
url,
displayFormat: 'focused',
style: {

/** High-level variables that mirror our existing branding APIs. Reusing the branding name here for familiarity. */
branding: {
primaryButton: {
/** Background color of primary button */
backgroundColor: '#FFDE00',
/** Text color of primary button */
color: '#000000'
}
},

/** High-level components we allow specific overrides for */
signingNavigationButton: {
finishText: 'Accept and E-sign',
/** 'bottom-left'|'bottom-center'|'bottom-right', default: bottom-right */
position: 'bottom-left'
}
}
});

signing.on('ready', (event) => {
console.log('ready event', event);

localStorage.setItem('isPageLoaded', 'true');
});

signing.on('sessionEnd', (event) => {
console.log('sessionend event', event);
if (event.sessionEndType === 'signing_complete') {
console.log('signing_complete', event);
docuSignUpdate(false, true);
} else if (event.sessionEndType === 'decline') {
console.log('decline', event);
} else {
// Other events
}
});

signing.mount('#agreement');
};

useEffect(() => {
console.log('DOCUSIGN RENDER');
localStorage.setItem('isPageLoaded', 'false');
loadDocuSign();
}, []);

setTimeout(() => {
console.log('Status after 15 seconds ', localStorage.getItem('isPageLoaded'));

if (localStorage.getItem('isPageLoaded') !== 'true') {
clearTimeout();
//Error in docusign pae loading,
/*
reason may be -
1. Presigned url expired
2. Already used url
3. Error in load docusign bundle script
4. Any network issue in connectivity
5. Wrong integration key or expired key
*/
}
}, timeoutMs);

return (
<>
<Script
onCreate={() => console.log('script onCreate')}
onError={() => console.log('script onError')}
onLoad={() => setScriptLoaded(true)}
url={docusignBundle}
/>

{isScriptLoaded && <div
className="docusign-agreement"
data-testid="agreement"
id="agreement"
/>}
</>
);
}

DocuSignUi.propTypes = {
docuSignUpdate: PropTypes.func.isRequired,
docUrl: PropTypes.string.isRequired,
integrationKey: PropTypes.string.isRequired
};

export default DocuSignUi;

 

Badge

I am also dealing with the same issue. To confirm, I didn’t receive any event for signing.on(“sessionEnd”). I only saw the session-ended ui with a message to return to my email where I received the link to sign. However, these links are being generated on the spot. No email is being sent. So we are stuck with no actionable abilities when the session ended.

I also have not received any error messages for the above mentioned scenarios:

 

/*
reason may be -
1. Presigned url expired
2. Already used url
3. Error in load docusign bundle script
4. Any network issue in connectivity
5. Wrong integration key or expired key
*/

/

Userlevel 2
Badge +7

I can reproduce you issue, I find the root cause is limit by CORS setting. when the redirect url is not set in frameAncestors, the redirect url will deny to access when all parameters are correct for :{{baseUrl}}/v2.1/accounts/{{accountId}}/envelopes/{{envelopeId}}/views/recipient. when one of the parameter is not correct, so there are no correct frameAncestors, all is deny. so the exception can’t catch.

 

FreeLink/甫连信息
🌍 DocuSign Partner | Partner Profile
🏆 2024 APAC Reseller Growth Partner of the Year
🔧 First globally to pass DocuSign eSignature Technical Consultant certification
🚀 Expertise in DocuSign integrations with in-house systems for leading enterprises across various industries.

Feel free to reach out for collaboration opportunities.

 

Reply