-
Notifications
You must be signed in to change notification settings - Fork 0
94 back end add exception handling and logging #100
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
Open
erfanul007
wants to merge
11
commits into
master
Choose a base branch
from
94-back-end-add-exception-handling-and-logging
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
e9227b5
Added initial logging configuration
erfanul007 402dd6a
Added logging to user app
erfanul007 f445197
Added logging and updated setting for log info
erfanul007 b1ba4f0
Merge branch 'master' into 94-back-end-add-exception-handling-and-log…
erfanul007 0b1eeb7
94: Added logging for problem app and suggestion app
erfanul007 edd5e1f
94: Fixed log exception variable name issue
erfanul007 51de003
94: Updated missing logging
erfanul007 0f24d1f
Merge branch 'master' into 94-back-end-add-exception-handling-and-log…
erfanul-infinitiBit bbf17a6
Updated generate suggestions try catch for merge conflict
erfanul-infinitiBit 324e9e5
Updated logger import and dockerfile
erfanul007 7b70589
Updated missing changes
erfanul007 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,6 @@ | ||
| import logging | ||
| logger = logging.getLogger(__name__) | ||
|
|
||
| from re import sub | ||
|
|
||
| from django.contrib.auth.models import User | ||
|
|
@@ -37,6 +40,9 @@ def get_user_score(request,username): | |
|
|
||
| except User.DoesNotExist: | ||
| return Response({'message': 'User not found'} ,status=404) | ||
| except Exception as ex: | ||
| logger.exception(ex) | ||
| return Response(status=500, data={'message': 'Some error occurred while getting user score.'}) | ||
erfanul007 marked this conversation as resolved.
Show resolved
Hide resolved
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or, you can raise the exception without having to return a 500 error. However, that's optional. |
||
|
|
||
|
|
||
| @api_view(['GET']) | ||
|
|
@@ -73,6 +79,9 @@ def get_user_stats(request, username): | |
|
|
||
| except User.DoesNotExist: | ||
| return Response({'message': 'User not found'} ,status=404) | ||
| except Exception as ex: | ||
| logger.exception(ex) | ||
| return Response(status=500, data={'message': 'Some error occurred while getting user stats.'}) | ||
|
|
||
|
|
||
| @api_view(['GET']) | ||
|
|
@@ -85,6 +94,9 @@ def get_user_strength(request, username): | |
| return Response(strengths[:5], status=200) | ||
| except User.DoesNotExist: | ||
| return Response({"message": "User not found"}, status=404) | ||
| except Exception as ex: | ||
| logger.exception(ex) | ||
| return Response(status=500, data={'message': 'Some error occurred while getting user strength.'}) | ||
|
|
||
|
|
||
| @api_view(['GET']) | ||
|
|
@@ -97,6 +109,9 @@ def get_user_weakness(request, username): | |
| return Response(weaknesses[-5:], status=200) | ||
| except User.DoesNotExist: | ||
| return Response({"message": "User not found"}, status=404) | ||
| except Exception as ex: | ||
| logger.exception(ex) | ||
| return Response(status=500, data={'message': 'Some error occurred while getting user weakness.'}) | ||
|
|
||
|
|
||
| @api_view(['GET']) | ||
|
|
@@ -117,3 +132,6 @@ def get_hardest_problem_solved(request, username): | |
| return Response(problem, status=200) | ||
| except User.DoesNotExist: | ||
| return Response({"message": "User not found"}, status=404) | ||
| except Exception as ex: | ||
| logger.exception(ex) | ||
| return Response(status=500, data={'message': 'Some error occurred while getting user hardest solved problem.'}) | ||
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this necessary? Nginx should run on docker port 80 without any errors.