Skip to content

Commit d9ed3c2

Browse files
committed
error handling and fixed redirects
1 parent 4ebba24 commit d9ed3c2

File tree

4 files changed

+37
-34
lines changed

4 files changed

+37
-34
lines changed

lib/click/controllers/eg006EmbedClickwrap.js

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66

77
const path = require("path");
8-
const { embedClickwrap, getActiveClickwraps } = require("../examples/embedClickwrap");
8+
const { embedClickwrap, getActiveClickwraps, getInactiveClickwraps } = require("../examples/embedClickwrap");
99
const validator = require("validator");
1010
const { getExampleByNumber } = require("../../manifestService");
1111
const dsConfig = require("../../../config/index.js").config;
@@ -53,21 +53,28 @@
5353
clickwrapId: req.body.clickwrapId,
5454
documentArgs: documentArgs
5555
};
56-
56+
const example = getExampleByNumber(res.locals.manifest, exampleNumber);
5757

5858
// Call the worker method
5959
try {
6060
results = await embedClickwrap(args);
6161
console.log(JSON.parse(JSON.stringify(results)));
6262
} catch (error) {
63-
const errorBody = error && error.response && error.response.body;
64-
// We can pull the DocuSign error code and message from the response body
65-
const errorCode = errorBody && errorBody.errorCode;
66-
const errorMessage = errorBody && errorBody.message;
67-
// In production, you may want to provide customized error messages and
68-
// remediation advice to the user
69-
res.render("pages/error", { err: error, errorCode, errorMessage });
70-
}
63+
if (embedClickwrap.agreementUrl == null) {
64+
const errorCode = error.message;
65+
const errorMessage = "The email address was already used to agree to this elastic template. Provide a different email address if you want to view the agreement and agree to it.";
66+
res.render("pages/error", {err: error, errorCode, errorMessage});
67+
} else {
68+
const errorBody = error && error.response && error.response.body;
69+
// We can pull the DocuSign error code and message from the response body
70+
const errorCode = errorBody && errorBody.errorCode;
71+
const errorMessage = errorBody && errorBody.message;
72+
73+
// In production, may want to provide customized error messages and
74+
// remediation advice to the user.
75+
res.render('pages/error', {err: error, errorCode, errorMessage});
76+
}
77+
}
7178
if (results) {
7279
// Save for use by other examples that need an clickwrapId
7380
const example = getExampleByNumber(res.locals.manifest, exampleNumber);
@@ -109,6 +116,7 @@
109116
example: example,
110117
sourceFile: sourceFile,
111118
clickwrapsData: await getActiveClickwraps(args),
119+
clickwrapsExist: await getInactiveClickwraps(args),
112120
sourceUrl: dsConfig.githubExampleUrl + 'click/examples/' + sourceFile,
113121
documentation: dsConfig.documentation + eg,
114122
showDoc: dsConfig.documentation

lib/click/examples/embedClickwrap.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,5 +68,17 @@
6868
return await accountApi.getClickwraps(args.accountId, {status: 'active'});
6969
}
7070

71-
module.exports = { getActiveClickwraps, embedClickwrap };
71+
const getInactiveClickwraps = async (args) => {
72+
// Call the Click API
73+
// Create Click API client
74+
const dsApiClient = new docusignClick.ApiClient();
75+
dsApiClient.setBasePath(args.basePath)
76+
dsApiClient.addDefaultHeader("Authorization", "Bearer " + args.accessToken);
77+
const accountApi = new docusignClick.AccountsApi(dsApiClient);
78+
79+
// Get a list of inactive clickwraps
80+
return await accountApi.getClickwraps(args.accountId, {status: 'inactive'});
81+
}
82+
83+
module.exports = { getInactiveClickwraps, getActiveClickwraps, embedClickwrap };
7284

views/pages/click-examples/eg006EmbedClickwrap.ejs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,16 @@
44

55
<% include("../../partials/functions") %>
66

7-
<% if (clickwrapsData.clickwraps.length == 0) { %>
7+
<% if (clickwrapsData.clickwraps.length == 0 && clickwrapsExist.clickwraps.length == 0) { %>
88
<%- formatString(example.RedirectsToOtherCodeExamples[0].RedirectText, formatString('href="eg00{0}"', example.RedirectsToOtherCodeExamples[0].CodeExampleToRedirectTo)) %>
99
<form class="eg" action="eg001" method="get">
1010
<%- include("../../partials/continueButton") %>
1111
</form>
12+
<% } else if (clickwrapsData.clickwraps.length == 0) { %>
13+
<%- formatString(example.RedirectsToOtherCodeExamples[1].RedirectText, formatString('href="eg00{0}"', example.RedirectsToOtherCodeExamples[1].CodeExampleToRedirectTo)) %>
14+
<form class="eg" action="eg002" method="get">
15+
<%- include("../../partials/continueButton") %>
16+
</form>
1217
<% } else { %>
1318
<form class="eg" action="" method="post" data-busy="form-download">
1419
<% if(example.Forms && example.Forms[0].FormName) { %>

views/pages/error_eg006.ejs

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)