Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show Error Toast Message whenever action execution fails from backend due to incorrect configurations #22

Merged
merged 3 commits into from
Jul 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,21 @@ const createActionContext = (context, action) => ({
},
});

export const checkForError = (response, error) => {
for (const trigger_name in response.resp.trigger_results) {
// Check for errors in the trigger response
if (!response.resp.trigger_results[trigger_name].error) {
// Check for errors in the actions configured
for (const action_result in response.resp.trigger_results[trigger_name].action_results) {
error = response.resp.trigger_results[trigger_name].action_results[action_result].error;
}
} else {
error = response.resp.trigger_results[trigger_name].error;
}
}
return error;
};

class ConfigureActions extends React.Component {
constructor(props) {
super(props);
Expand Down Expand Up @@ -112,9 +127,14 @@ class ConfigureActions extends React.Component {
query: { dryrun: false },
body: JSON.stringify(testMonitor),
});
if (!response.ok) {
console.error('There was an error trying to send test message', response.resp);
backendErrorNotification(notifications, 'send', 'test message', response.resp);
let error = null;
if (response.ok) {
error = checkForError(response, error);
}
if (error || !response.ok) {
const errorMessage = error == null ? response.resp : error;
console.error('There was an error trying to send test message', errorMessage);
backendErrorNotification(notifications, 'send', 'test message', errorMessage);
}
} catch (err) {
console.error('There was an error trying to send test message', err);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/

/*
* Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

import { checkForError } from './ConfigureActions';

const error =
'java.io.IOException: Failed: HttpResponseProxy{HTTP/1.1 403 Forbidden [Content-Type: application/json, Content-Length: 82, Connection: keep-alive, Date: Fri, 02 Jul 2021 03:54:57 GMT, x-amzn-ErrorType: ForbiddenException';

const noErrorInResponse = {
resp: {
monitor_name: 'TestMonitor',
period_start: 1625198037084,
period_end: 1625198097084,
error: null,
input_results: {
results: [],
error: null,
},
trigger_results: {
PgxaZXoB3e90jg4z8ga8: {
name: '',
triggered: true,
error: null,
action_results: {
PwxaZXoB3e90jg4z8ga8: {
id: 'PwxaZXoB3e90jg4z8ga8',
name: 'sdlkmdslfdsfds',
output: {},
throttled: false,
executionTime: 1625198097035,
error: null,
},
},
},
},
},
};

const errorInActionResponse = {
resp: {
monitor_name: 'TestMonitor',
period_start: 1625198037084,
period_end: 1625198097084,
error: null,
input_results: {
results: [],
error: null,
},
trigger_results: {
PgxaZXoB3e90jg4z8ga8: {
name: '',
triggered: true,
error: null,
action_results: {
PwxaZXoB3e90jg4z8ga8: {
id: 'PwxaZXoB3e90jg4z8ga8',
name: 'sdlkmdslfdsfds',
output: {},
throttled: false,
executionTime: 1625198097035,
error: error,
},
},
},
},
},
};

const errorInTriggerResponse = {
resp: {
monitor_name: 'TestMonitor',
period_start: 1625198037084,
period_end: 1625198097084,
error: null,
input_results: {
results: [],
error: null,
},
trigger_results: {
PgxaZXoB3e90jg4z8ga8: {
name: '',
triggered: true,
error: error,
action_results: {
PwxaZXoB3e90jg4z8ga8: {
id: 'PwxaZXoB3e90jg4z8ga8',
name: 'sdlkmdslfdsfds',
output: {},
throttled: false,
executionTime: 1625198097035,
error: null,
},
},
},
},
},
};

describe('checkForError', () => {
test('return no error in response', () => {
expect(checkForError(noErrorInResponse, null)).toBe(null);
});

test('return error in action response', () => {
expect(checkForError(errorInActionResponse, null)).toBe(error);
});

test('return error in trigger response', () => {
expect(checkForError(errorInTriggerResponse, null)).toBe(error);
});
});