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

[MDS-5607] - Exception handling + Email Notification #2824

Merged
merged 20 commits into from
Dec 4, 2023

Conversation

isuru-aot
Copy link
Contributor

@isuru-aot isuru-aot commented Nov 24, 2023

Objective

MDS-5607
MDS-5617

Why are you making this change? Provide a short explanation and/or screenshots

Hackathon work item for exception handling.

Items covered:

  • Added custom exceptions to mines namespace (resources and models)
  • Added E-mail with VIEW_ALL rights
  • Added notify admin feature when an error occurred (in FE)
  • Added ERROR_NOTIFY_RECIPIENTS environment variable to configure email address for error notification.

@isuru-aot isuru-aot changed the title Hckthn mds 5607 [MDS-5607] - Exception handling + Email Notification Nov 25, 2023
@isuru-aot isuru-aot assigned taraepp and asinn134 and unassigned taraepp and asinn134 Nov 28, 2023
@isuru-aot isuru-aot marked this pull request as ready for review November 28, 2023 22:06
from app.api.utils.resources_mixins import UserMixin
from app.api.exception.mds_core_api_exceptions import MDSCoreAPIException

class EmailResource(Resource, UserMixin):
Copy link
Collaborator

@simensma-fresh simensma-fresh Nov 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest that we maybe do not expose this as a generic way of sending emails accross the app. I've got some concerns with this in terms of potential abuse, as this would in essence allow anyone with access to send arbitrary emails on behalf of the mds team. The other concern I have would be that we allow plain html as input which would open up for html injection

As an alternative we could make this a specific "Report Error" endpoint that takes in the required fields so we can do some basic validation on it and create an email template that is specific for the error reporting in the templates folder which would escape what's passed in.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Simen,
Added an endpoint for report-error, and only the error details are accepted in that. And email get sent with user info from BE. And the html template is used for the email content.

<p><b>Business Error:</b> ${business_message}</P>
<p>
<b>Reporter's Name:</b> ${user.given_name} ${user.family_name}</br>
<b>Reporter's Email:</b> ${user.email}</br>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the change suggested above to make the email endpoint specific to error reporting, I would suggest trying to get these details (user email / username etc) from the users token on the endpoint level so you would not be able to send these on behalf of another user

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is addressed. Thanks.

message: formatErrorMessage(error?.response?.data?.message ?? String.ERROR),
description: <p style={{ color: 'grey' }}>If you think this is a system error please help us to improve by informing the system Admin</p>,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we put this behind a feature flag in case we decide on doing any iterations on this before releasing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a feature flag from FE. Thanks

message: formatErrorMessage(error?.response?.data?.message ?? String.ERROR),
duration: 10,
});
console.error('Detailed Error: ', error?.response?.data?.detailed_error)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missed a console log 😜

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @matbusby-fw,
Actually, I kept this purposely, as the detailed error will not be visible to FE anymore with this change. But it may not good practice. Shall I remove it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I don't suppose it will hurt anything, but it might be of limited usefulness to us since we're not going to be seeing the user's console.

Copy link
Collaborator

@matbusby-fw matbusby-fw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good! I'm excited about this feature!

@isuru-aot isuru-aot merged commit 3ad7dbd into develop Dec 4, 2023
11 checks passed
@isuru-aot isuru-aot deleted the hckthn-mds-5607 branch December 4, 2023 14:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants