Intercepting (and modifying) API calls to IDmission’s backend with onBeforeSubmit
Each customer flow documented above includes an optional onBeforeSubmit
prop, which bears the type signature (request: SubmissionRequest) => Promise<SubmissionRequest>
. This can be useful if you would like to include some custom functionality that interrupts the WebSDK’s outgoing request to IDmission’s servers, allowing you a chance to modify the request before it is dispatched.
To delay the submission until some async condition has been met by your application:
onBeforeSubmit: () => new Promise((resolve) => {
// do whatever you want in here, websdk will delay submission until you call:
resolve()
})
Calling resolve()
without an argument as shown above will result in no modification being made to the request that will be sent to IDmission’s servers.
To alter the submission request before it goes out:
onBeforeSubmit: (req) => new Promise((resolve) => {
req.myRandomExtraThing = '123'
resolve(req)
})
Note that you will receive the request as a parameter to onBeforeSubmit
, and must resolve
with the altered version in order for your changes to be committed.
If the promise is rejected or an error is thrown, that rejection value or error will be printed to the logs and the request will be not be sent. The onRequestFailure
hook will be fired with the error that came from your code.