-
-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #386 from DemocracyLab/error_500_logging
Add Error page with custom message for OAuth signup failure
- Loading branch information
Showing
8 changed files
with
116 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// @flow | ||
|
||
import React from 'react'; | ||
import type {Dictionary} from "../types/Generics.jsx"; | ||
import urlHelper from "../utils/url.js"; | ||
|
||
type ErrorArgs = {| | ||
errorType: string | ||
|} | ||
|
||
type State = {| | ||
errorArgs: ErrorArgs | ||
|}; | ||
|
||
const ErrorMessagesByType: Dictionary<(ErrorArgs) => string> = { | ||
MissingOAuthFieldError: (errorArgs: ErrorArgs) => { | ||
const missingFields: string = decodeURI(errorArgs.missing_fields); | ||
return `Sign up failed, as your account is missing the following fields: ${missingFields}. ` + | ||
`Please update your ${errorArgs.provider} profile with this information or use another method to sign up for DemocracyLab. Thank you!`; | ||
} | ||
}; | ||
|
||
function getErrorMessage(errorArgs: ErrorArgs): string { | ||
if(errorArgs.errorType in ErrorMessagesByType) { | ||
return ErrorMessagesByType[errorArgs.errorType](errorArgs); | ||
} else { | ||
return "Error"; | ||
} | ||
} | ||
|
||
class ErrorController extends React.Component<{||}, State> { | ||
constructor(): void { | ||
super(); | ||
this.state = { | ||
errorArgs: urlHelper.getSectionArgs().args | ||
}; | ||
} | ||
|
||
render(): React$Node { | ||
return ( | ||
<div> | ||
{getErrorMessage(this.state.errorArgs)} | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default ErrorController; |
This file contains 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 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 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 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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import sys | ||
from django.shortcuts import redirect | ||
from common.helpers.constants import FrontEndSection | ||
from common.helpers.dictionaries import merge_dicts | ||
from common.helpers.front_end import section_url | ||
|
||
|
||
class ReportableError(Exception): | ||
"""Exception raised that needs to be logged and sent to a front end error page | ||
Attributes: | ||
message -- explanation of the error to be reported in the logs | ||
front_end_args -- arguments to be surfaced on the front end error page | ||
""" | ||
|
||
def __init__(self, message, front_end_args): | ||
self.message = message | ||
self.front_end_args = front_end_args or {} | ||
|
||
|
||
def handle500(request): | ||
exception_type, exception, traceback = sys.exc_info() | ||
if isinstance(exception, ReportableError): | ||
# Log message | ||
print("Error(500): " + exception.message) | ||
error_args = merge_dicts(exception.front_end_args, {'errorType': type(exception).__name__}) | ||
# Redirect to Error page | ||
return redirect(section_url(FrontEndSection.Error, error_args)) | ||
else: | ||
return redirect(section_url(FrontEndSection.Error)) | ||
|
This file contains 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 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