Skip to content

Commit

Permalink
UI: Add more descriptive message upon submitting invalid credentials
Browse files Browse the repository at this point in the history
Issue: #3942
PR: #3977
  • Loading branch information
ilija-lazoroski committed Dec 22, 2023
1 parent 4fe4bed commit 7bcf0af
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions monkey/monkey_island/cc/ui/src/components/pages/ConfigurePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class ConfigurePageComponent extends AuthComponent {
this.state = {
configuration: {},
credentials: {credentialsData: [], errors: [], id: null},
credentialsErrors: [],
masqueStrings: {},
currentFormData: {},
importCandidateConfig: null,
Expand Down Expand Up @@ -409,6 +410,20 @@ class ConfigurePageComponent extends AuthComponent {
)
.then(res => {
if (!res.ok) {
res.json().then((result)=>{
let errorMessages = result.errors.map(error => {
return `${error.message.split(', ').pop()}`;
});
const messageCountMap = {};
errorMessages.map((message) => {
messageCountMap[message] = (messageCountMap[message] || 0) + 1;
});
this.setState({
credentialsErrors: Object.entries(messageCountMap)
.map(([errorMessage, count]) =>
(count > 1 ? `${count} ${_.lowerFirst(errorMessage)}` : `${errorMessage}`))
});
});
throw Error()
}
return res;
Expand Down Expand Up @@ -573,6 +588,11 @@ class ConfigurePageComponent extends AuthComponent {
<div className='alert alert-danger'>
<FontAwesomeIcon icon={faExclamationCircle} style={{'marginRight': '5px'}}/>
An invalid configuration file was imported or submitted. One or more of the credentials are invalid.
{ this.state.credentialsErrors.length !== 0 ?
<ul>
{this.state.credentialsErrors.map(error => <li key={nanoid()}>{error}</li>)}
</ul> : ''
}
</div>
: ''}
{this.state.lastAction === 'invalid_configuration' ?
Expand Down

0 comments on commit 7bcf0af

Please sign in to comment.