fix: Improve readability of "enable this API" messages#10375
fix: Improve readability of "enable this API" messages#10375kevmoo wants to merge 1 commit intofirebase:mainfrom
Conversation
Fixes firebase#10366 The existing bits get easily buried in the output. Make it super easy for the user to discover. If cloud changes this text, the backup behavior is not catastrophic, either.
There was a problem hiding this comment.
Code Review
This pull request modifies src/responseToError.ts to improve the readability of error messages by inserting double newlines before specific phrases related to API enablement. The review feedback suggests using a single global regular expression instead of multiple string-based replacements to ensure all occurrences are handled and to simplify the code logic.
| errorMessage = errorMessage.replace("Enable it by visiting", "\n\nEnable it by visiting"); | ||
| errorMessage = errorMessage.replace( | ||
| "If you enabled this API recently", | ||
| "\n\nIf you enabled this API recently", | ||
| ); |
There was a problem hiding this comment.
The current implementation using String.prototype.replace() with a string literal only replaces the first occurrence of the target text. While it is unlikely that these specific phrases appear multiple times in a single error message, using a global regular expression is more robust and ensures all occurrences are formatted as intended. Additionally, using a single regex with a capture group simplifies the logic and handles both phrases in one pass.
| errorMessage = errorMessage.replace("Enable it by visiting", "\n\nEnable it by visiting"); | |
| errorMessage = errorMessage.replace( | |
| "If you enabled this API recently", | |
| "\n\nIf you enabled this API recently", | |
| ); | |
| errorMessage = errorMessage.replace(/(Enable it by visiting|If you enabled this API recently)/g, "\n\n$1"); |
Fixes #10366
The existing bits get easily buried in the output. Make it super easy for the user to discover.
If cloud changes this text, the backup behavior is not catastrophic, either.