Skip to content

Commit

Permalink
Clearer error message for users
Browse files Browse the repository at this point in the history
  • Loading branch information
ionwyn committed May 16, 2024
1 parent 0b87abc commit 7a0a11b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
16 changes: 15 additions & 1 deletion api/Hmcr.Api/Controllers/SaltReportsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,22 @@ public async Task<IActionResult> CreateSaltReportAsync([FromBody] SaltReportDto
}
catch (Exception ex)
{
return StatusCode(500, "An internal error occurred. Please try again later.");
// Get the inner exception message if it exists
var innerExceptionMessage = ex.InnerException?.Message ?? "Please contact an administrator to resolve this issue.";

Console.Error.WriteLine($"Exception: {ex.Message}");
if (ex.InnerException != null)
{
Console.Error.WriteLine($"Inner Exception: {innerExceptionMessage}");
}

return StatusCode(500, new
{
message = "An internal error occurred. Please try again later.",
error = $"500 Internal Server Error: {innerExceptionMessage}"
});
}

}


Expand Down
20 changes: 15 additions & 5 deletions client/src/js/components/SaltReporting.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const SaltReporting = ({ currentUser }) => {
const [loading, setLoading] = useState(false);
const [showSaltReportStatusModal, setShowSaltReportStatusModal] = useState(false);
const [saltReportCompleteMessage, setSaltReportCompleteMessage] = useState(null);
const [saltReportSuccess, setSaltReportSuccess] = useState(false);

var defaultSearchOptions = {
fromDate: moment().subtract(1, 'years').format('YYYY-MM-DD'),
Expand Down Expand Up @@ -48,11 +49,15 @@ const SaltReporting = ({ currentUser }) => {
const stagingTableName = 'HMR_SALT_REPORT';
const apiPath = Constants.REPORT_TYPES[stagingTableName].api;
const response = await api.instance.post(apiPath, values);
setLoading(false);

setSaltReportCompleteMessage(`Report successfully created. Details: ${response.status} ${response.statusText}.`);
setSaltReportSuccess(true);
} catch (error) {
console.error('Submitting salt report failed:', error);
showValidationErrorDialog(error.response?.data || 'An unexpected error occurred');
setLoading(false);
console.error(error);
setSaltReportCompleteMessage(`Report submission failed. ${error.response?.data.error}`);
setSaltReportSuccess(false);
} finally {
setLoading(false);
}
Expand Down Expand Up @@ -139,10 +144,15 @@ const SaltReporting = ({ currentUser }) => {
title="Report Submission"
disableClose={loading}
>
{saltReportCompleteMessage ? (
{!loading && saltReportCompleteMessage ? (
<Alert color="info">
{saltReportCompleteMessage} Provide a copy of current Salt Management Plan following form submission to:{' '}
<a href="mailto: Maintenance.Programs@gov.bc.ca">Maintenance.Programs@gov.bc.ca</a>
{saltReportCompleteMessage}
{saltReportSuccess && (
<>
Provide a copy of current Salt Management Plan following form submission to:{' '}
<a href="mailto:Maintenance.Programs@gov.bc.ca">Maintenance.Programs@gov.bc.ca</a>
</>
)}
</Alert>
) : (
<PageSpinner />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as Yup from 'yup';
const decimalWithPrecision = (precision) => {
return Yup.number()
.nullable(true)
.max(99999999.99, 'Value must be less than or equal to 99,999,999.99')
.test(
'is-decimal',
`Invalid format: number must have no more than ${precision} decimal places and be non-negative`,
Expand Down

0 comments on commit 7a0a11b

Please sign in to comment.