Skip to content

Commit

Permalink
update error status and update error string
Browse files Browse the repository at this point in the history
  • Loading branch information
dnlbui committed Sep 26, 2024
1 parent b68c019 commit 91c2f20
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
8 changes: 3 additions & 5 deletions api/handlers/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,16 +131,14 @@ export default function configureNodeHandlers(apiRouter: Router) {


console.log('Executing operator-cli stake_info...');
const output = execFileSync('operator-cli', ['stake_info', address], { encoding: 'utf8' });
const output = execFileSync('operator-cli', ['stake_info', address], { encoding: 'utf8' })

// Check for specific error message
// Case where query was valid but no stake info was found
if (output.includes('Error: No stake information found')) {
console.log('Entered error handling');
if (output === 'No stake information found. Please fund the account and try again.') {
// Check if the response headers have already been sent
if (!res.headersSent) {
console.log('Sending 500 response: Account not found');
res.status(500).json({ errorMessage: 'Account not found. Please ensure the account has been created and funded.', errorDetails: '' });
res.status(404).json({ errorMessage: 'Account not found. Please ensure the account has been funded.', errorDetails: '' });
}
return;
}
Expand Down
2 changes: 1 addition & 1 deletion hooks/fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const fetcher = async <T>(input: RequestInfo | URL,
const data = await res.json();
if (res.status === 403) {
authService.logout(apiBase);
} else if (input.toString().includes('account') && res.status === 500 && data.errorMessage === `Account not found. Please ensure the account has been created and funded.`) {
} else if (input.toString().includes('account') && res.status === 404 && data.errorMessage === `Account not found. Please ensure the account has been funded.`) {
throw new Error('No stake information found. Please fund the account and try again.');
} else if (res.status === 500) {
showErrorMessage('Sorry, something went wrong. Please report this issue to our support team so we can investigate and resolve the problem.');
Expand Down

0 comments on commit 91c2f20

Please sign in to comment.