You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Handle proposal finalize timeout by confirming completion - #148
The enterPaymentTxId and enterProposalHash functions now catch errors and log them using logAxiosError. However, the error handling could be improved by providing more specific error messages to the user, potentially differentiating between network errors, API errors, and validation errors. Consider adding more robust error handling and user feedback mechanisms.
constenterPaymentTxId=async(data)=>{swal.fire({title: 'Creating submit command',showConfirmButton: false,willOpen: ()=>{swal.showLoading();}});const{ paymentTxId }=data;letprepareObjectProposal;try{constupdateResponse=awaitupdateProposal(proposalUid,{txId: paymentTxId});prepareObjectProposal=updateResponse?.data?.proposal?.prepareObjectProposal;if(!prepareObjectProposal){thrownewError('The prepare payload is missing from the update response.');}constsubmitResponse=awaitsubmitProposal(proposalUid,{ ...prepareObjectProposal,txId: paymentTxId});constcommandSubmit=submitResponse?.data?.commandSubmit;if(!commandSubmit){thrownewError('Submit command was not returned by the API.');}setSubmitCommand(commandSubmit);awaitswal.fire({icon: 'success',title: 'Submit command created',timer: 2000,showConfirmButton: false});setUseCollapse(true);setCollapse(false);}catch(error){logAxiosError('ProposalForm::enterPaymentTxId',error,{
proposalUid,
paymentTxId,hasPreparePayload: Boolean(prepareObjectProposal)});consterrorMessage=getAxiosErrorMessage(error,'Unable to create submit command.');constfooter=getAxiosErrorFooter(error);awaitswal.fire({icon: 'error',title: 'There was an error',text: errorMessage,
footer
});}}constconfirmProposalCompletion=async(proposalId,expectedHash)=>{if(!proposalId){return{isCompleted: false};}try{constresponse=awaitgetOneProposal(proposalId);constsavedProposal=response?.data?.proposal;if(!savedProposal){return{isCompleted: false};}constnormalizedExpectedHash=typeofexpectedHash==='string'
? expectedHash.trim().toLowerCase()
: '';constcandidateHashes=[savedProposal.hash,savedProposal.proposalHash,savedProposal.proposal_hash,].filter((value)=>typeofvalue==='string'&&value.trim().length>0).map((value)=>value.trim().toLowerCase());constmatchesHash=Boolean(normalizedExpectedHash&&candidateHashes.includes(normalizedExpectedHash));constisComplete=Boolean(savedProposal.complete===true||savedProposal.status==='complete'||savedProposal.state==='complete'||matchesHash);return{isCompleted: isComplete,
matchesHash,resolvedHash: candidateHashes[0]||null,};}catch(statusError){logAxiosError('ProposalForm::confirmProposalCompletion',statusError,{ proposalId });return{isCompleted: false};}}/** * Function that gets the proposal hash and creates the new proposal * @function * @param {{proposalHash: string}} data proposalHash from the input */constenterProposalHash=async(data)=>{swal.fire({title: 'Creating the proposal',showConfirmButton: false,willOpen: ()=>{swal.showLoading();}});const{ proposalHash }=data;try{awaitupdateProposal(proposalUid,{hash: proposalHash,complete: true});awaitswal.fire({icon: 'success',title: 'The proposal was created',timer: 2000,showConfirmButton: false});history.push('/governance');}catch(error){logAxiosError('ProposalForm::enterProposalHash',error,{
proposalUid,
proposalHash
});consterrorMessage=getAxiosErrorMessage(error,'There was an error please try again');constfooter=getAxiosErrorFooter(error);constcompletionCheck=awaitconfirmProposalCompletion(proposalUid,proposalHash);if(completionCheck.isCompleted){constfooterDetails=[errorMessage];if(footer){footerDetails.push(footer);}if(completionCheck.resolvedHash){footerDetails.push(`Hash detected: ${completionCheck.resolvedHash}`);}awaitswal.fire({icon: 'warning',title: 'Proposal creation confirmed after timeout',text: 'The proposal appears to have been registered even though the server timed out. You can confirm it from the governance page.',footer: footerDetails.join('<br />'),});history.push('/governance');return;}awaitswal.fire({icon: 'error',title: 'There was an error please try again',text: errorMessage,
footer
});}
The normalizeResponseData function attempts to parse JSON responses. While this is a good approach for handling various data types, consider adding more robust error handling within the try...catch block to prevent unexpected behavior if the response is not valid JSON. Log any parsing errors for debugging purposes.
The catch block lacks detailed error handling. Enhance it to provide more informative error messages to the user, including potential API error details and a fallback message. Consider using the newly introduced error handling utilities from errorHandler.js to improve error reporting.
Why: The suggestion improves the error handling by using the new error handling utilities from errorHandler.js. This makes the error messages more informative and user-friendly. The improvement is good, but not critical.
Medium
Add more context to logs
The error handling in enterPaymentTxId is good, but could be improved by adding more context to the logged error. Include information about the proposal's status and any relevant data. This will help with debugging and identifying the root cause of errors. Consider adding a check for the existence of updateResponse and submitResponse before accessing their properties.
const enterPaymentTxId = async (data) => {
- swal.fire({- title: 'Creating submit command',- showConfirmButton: false,- willOpen: () => {- swal.showLoading();- }- });+ swal.fire({+ title: 'Creating submit command',+ showConfirmButton: false,+ willOpen: () => {+ swal.showLoading();+ }+ });+ const { paymentTxId } = data;+ let prepareObjectProposal;+ try {+ const updateResponse = await updateProposal(proposalUid, { txId: paymentTxId });+ if (!updateResponse) {+ throw new Error('Update proposal request failed.');+ }+ prepareObjectProposal = updateResponse?.data?.proposal?.prepareObjectProposal;+ if (!prepareObjectProposal) {+ throw new Error('The prepare payload is missing from the update response.');+ }+ const submitResponse = await submitProposal(proposalUid, { ...prepareObjectProposal, txId: paymentTxId });+ if (!submitResponse) {+ throw new Error('Submit proposal request failed.');+ }+ const commandSubmit = submitResponse?.data?.commandSubmit;+ if (!commandSubmit) {+ throw new Error('Submit command was not returned by the API.');+ }+ setSubmitCommand(commandSubmit);+ await swal.fire({+ icon: 'success',+ title: 'Submit command created',+ timer: 2000,+ showConfirmButton: false+ });+ setUseCollapse(true);+ setCollapse(false);+ } catch (error) {+ logAxiosError('ProposalForm::enterPaymentTxId', error, {+ proposalUid,+ paymentTxId,+ hasPreparePayload: Boolean(prepareObjectProposal),+ updateResponse: updateResponse ? 'Success' : 'Failed',+ submitResponse: submitResponse ? 'Success' : 'Failed'+ });+ const errorMessage = getAxiosErrorMessage(error, 'Unable to create submit command.');+ const footer = getAxiosErrorFooter(error);+ await swal.fire({+ icon: 'error',+ title: 'There was an error',+ text: errorMessage,+ footer+ });+ }+};- const { paymentTxId } = data;- let prepareObjectProposal;-- try {- const updateResponse = await updateProposal(proposalUid, { txId: paymentTxId });- prepareObjectProposal = updateResponse?.data?.proposal?.prepareObjectProposal;-- if (!prepareObjectProposal) {- throw new Error('The prepare payload is missing from the update response.');- }-- const submitResponse = await submitProposal(proposalUid, { ...prepareObjectProposal, txId: paymentTxId });- const commandSubmit = submitResponse?.data?.commandSubmit;-- if (!commandSubmit) {- throw new Error('Submit command was not returned by the API.');- }-- setSubmitCommand(commandSubmit);-- await swal.fire({- icon: 'success',- title: 'Submit command created',- timer: 2000,- showConfirmButton: false- });-- setUseCollapse(true);- setCollapse(false);- } catch (error) {- logAxiosError('ProposalForm::enterPaymentTxId', error, {- proposalUid,- paymentTxId,- hasPreparePayload: Boolean(prepareObjectProposal)- });-- const errorMessage = getAxiosErrorMessage(error, 'Unable to create submit command.');- const footer = getAxiosErrorFooter(error);-- await swal.fire({- icon: 'error',- title: 'There was an error',- text: errorMessage,- footer- });- }-}-
Suggestion importance[1-10]: 5
__
Why: The suggestion adds more context to the error logs, which can be helpful for debugging. However, the added checks for updateResponse and submitResponse might be redundant if the catch block already handles potential errors from those functions. The impact is moderate.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
User description
Summary
getOneProposalto confirm whether a proposal completed even if the finalize call times outTesting
https://chatgpt.com/codex/tasks/task_e_68d29edc1e188320a5c3c44f893cb875
PR Type
Enhancement, Bug fix
Description
Improved error handling in API requests.
Added proposal completion confirmation.
Enhanced user experience with warnings.
Improved logging of Axios errors.
Diagram Walkthrough
flowchart LR A[API Request] --> B{Success}; A --> C[Error Handling]; C --> D[Log Axios Error]; C --> E[User Feedback]; F[Proposal Completion Confirmation] --> G{Success/Failure};File Walkthrough
errorHandler.js
Added Axios Error Handling Utilitiessrc/utils/errorHandler.js
Axios errors.
request.js
Improved API Request Error Handling and Added Proposal CompletionChecksrc/utils/request.js
ProposalForm.jsx
Enhanced Proposal Form with Improved Error Handling and CompletionChecksrc/components/proposal/ProposalForm.jsx
enterPaymentTxIdandenterProposalHashfunctions.