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

chore: add friendly message mapping #3079

Merged
merged 1 commit into from
Mar 31, 2025

Conversation

shon-button
Copy link
Contributor

@shon-button shon-button commented Mar 24, 2025

Addresses: 634

🚀 Impact:

  • Transforms back-end errors such a emission; fuelName;s gasType into user friendly message.

🔬 Local Testing:

Tests Set-Up:

  1. Start the API server:

    cd bc_obps
    make reset_db
    make run
  2. Start the app development server:

    cd bciers && yarn dev-all
  3. Navigate to http://localhost:3000

  4. Click the "Log in with Business BCeID" button

  5. Log in using bc-cas-dev

Test: User friendly error messages

Steps

  1. Navigate to http://localhost:3000/reporting/reports/
  2. Select operation Bugle SFO - Registered
  3. Click Continue
  4. Navigate to activities, ex: http://localhost:3000/reporting/reports/1/facilities/f486f2fb-62ed-438d-bb3e-0819b51e3aff/activities
  5. Select General stationary combustion excluding line tracing\General stationary combustion of fuel or waste with production of useful energy
  6. Click Save and Continue

Expected Result


Error displays: "Fuel is expecting 'Fuel Name' data." (transformed back-end error message)
image

  1. Complete Fuel Name
  2. Click Save and Continue

Expected Result


Error displays: "Emission is expecting 'Gas Type' data." (transformed back-end error message)
image

  1. Complete Gas Type
  2. Click Save and Continue

Expected Result


Error displays: "Emission is expecting 'Emission' data." (transformed back-end error message)
image

  1. Complete Emission
  2. Click Save and Continue

Expected Result


Error displays: "Emission is expecting methodology data" (direct back-end error message)
image

  1. Navigate to sign-off, ex: http://localhost:3000/reporting/reports/1/sign-off
  2. Complete the form and click Submit report

Expected Result


Error displays: Verification information must be completed with this report. Please complete the Verification page.
image

  1. Navigate to verification, ex: http://localhost:3000/reporting/reports/1/verification
  2. Complete the form and click Save and Continue
  3. Navigate to sign-off, ex: http://localhost:3000/reporting/reports/1/sign-off
  4. Complete the form and click Submit report

Expected Result


Error displays: A verification statement must be uploaded with this report. Please upload a verification statement on the Attachments page.
image

@shon-button shon-button force-pushed the chore/634-friendly-be-message branch 3 times, most recently from f02a3fb to 934f6e6 Compare March 26, 2025 17:51
Comment on lines 29 to 44
for (const key of Object.keys(reportValidationMessagesMap)) {
if (errorStr.includes(key)) {
return key as ReportValidationMessageKey;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This will just introduce some potential weirdness, if we don't explicitely define where the keys we're trying to catch come from. I think we should at the very least make sure that our ReportActivityService throws errors with the right key, that we can then match here. A lot of error messages might contain "emission"!

ReportSubmissionService raises specific exception messages to be caught on the frontend, and we'd want to do the same, as an example

Copy link
Contributor Author

@shon-button shon-button Mar 26, 2025

Choose a reason for hiding this comment

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

@pbastia

Thank-you and in agreement that your ReportSubmissionService errors are a good pattern to follow...

In this particular case my choice was specifically not to make any changes to the ReportActivitySaveService (to avoid possible regression bugs etc.) but, still provide a nicer message to the user than the service generated errors: fuelName; gasType; emission.

I have refined the utils function for your re-consideration - thanks!

@shon-button shon-button force-pushed the chore/634-friendly-be-message branch from 934f6e6 to eb831af Compare March 26, 2025 19:18
@shon-button shon-button force-pushed the chore/634-friendly-be-message branch from eb831af to ba8d9e9 Compare March 27, 2025 09:36
@zoeyli-46
Copy link

Hey @shon-button as part of the new error messages, is it doable for the Activities pages back end error messages be renamed to "< field name > is required" so it is uses plain language? i.e., "Emission 1's Fuel name is required" "Emission 1's methodology is required"

@shon-button shon-button force-pushed the chore/634-friendly-be-message branch 2 times, most recently from 7a8dc50 to c286ae7 Compare March 28, 2025 12:47
@shon-button
Copy link
Contributor Author

Hey @shon-button as part of the new error messages, is it doable for the Activities pages back end error messages be renamed to "< field name > is required" so it is uses plain language? i.e., "Emission 1's Fuel name is required" "Emission 1's methodology is required"

@zoeyli-46
cc: @pbastia

Hi Zoey,
I don't think this "quick and easy" solution will satisfy the requirement your looking for...if we want location specific error messaging we might have to consider implementing front-end validations rather than/or as well as more robust back-end error returns.

I will put the related issue card back in the backlog with Backlog Refinement tag.

@shon-button
Copy link
Contributor Author

Note: re-opening for further consideration of merging based on...
ZL:

Hey Shon! i saw your response on the PR. if we cant be specific with a "fuel 1" etc. then could we just reword your suggestion of ""Fuel is expecting 'Fuel Name' data."" to "Fuel is missing Fuel name"? 
""Emission is expecting 'Gas Type' data."" > Emission is missing Gas Type
"Emission is expecting 'Emission' data" > Emission is missing Emission

@shon-button shon-button force-pushed the chore/634-friendly-be-message branch 2 times, most recently from 3dcb7c0 to ca2b60e Compare March 28, 2025 20:08
@shon-button shon-button force-pushed the chore/634-friendly-be-message branch from ca2b60e to 7217bed Compare March 31, 2025 11:19
chore: prettier

chore: cleanup

chore: cleanup

chore: cleanup

chore: cleanup
@shon-button shon-button force-pushed the chore/634-friendly-be-message branch from 83c9fc4 to cf729c4 Compare March 31, 2025 11:24
@shon-button shon-button merged commit c5d871b into develop Mar 31, 2025
22 checks passed
@shon-button shon-button deleted the chore/634-friendly-be-message branch March 31, 2025 11:37
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.

3 participants