|
|
@@ -12,7 +12,7 @@ export const useAp2iErrorHandler = () => {
|
|
|
* @returns Processed error message
|
|
|
*/
|
|
|
const processApiError = (error: unknown): string => {
|
|
|
- let errorMessage =
|
|
|
+ const defaultErrorMessage =
|
|
|
"Une erreur s'est produite. Veuillez réessayer plus tard ou nous contacter directement."
|
|
|
|
|
|
// Try to extract the specific error message from the API response
|
|
|
@@ -27,7 +27,7 @@ export const useAp2iErrorHandler = () => {
|
|
|
if (errorData.detail) {
|
|
|
// Check if it's the specific error about organization already existing
|
|
|
const organizationExistsRegex =
|
|
|
- /Handling ".*" failed: An organization named '(.+)' already exists in (.+)/
|
|
|
+ /An organization named '(.+)' already exists in (.+)/
|
|
|
const match = errorData.detail.match(organizationExistsRegex)
|
|
|
|
|
|
if (match) {
|
|
|
@@ -35,17 +35,17 @@ export const useAp2iErrorHandler = () => {
|
|
|
const organizationName = match[1]
|
|
|
const cityName = match[2]
|
|
|
const translationKey =
|
|
|
- "An organization named '%s' already exists in %s"
|
|
|
+ "An organization named '{0}' already exists in {1}"
|
|
|
|
|
|
const translatedMessage = $i18n.t(translationKey, [
|
|
|
organizationName,
|
|
|
cityName,
|
|
|
])
|
|
|
- errorMessage = translatedMessage as string
|
|
|
- } else {
|
|
|
- // For other errors, use translation if available, otherwise use the original message
|
|
|
- if (!errorData.detail) return errorData.detail
|
|
|
+ console.log(translatedMessage, organizationName, cityName)
|
|
|
|
|
|
+ // Return only the translated message
|
|
|
+ return translatedMessage as string
|
|
|
+ } else {
|
|
|
// Remove the "Handling ... failed:" part if present
|
|
|
let cleanedDetail = errorData.detail
|
|
|
const handlingFailedRegex = /Handling ".*" failed: (.*)/
|
|
|
@@ -55,12 +55,21 @@ export const useAp2iErrorHandler = () => {
|
|
|
cleanedDetail = handlingMatch[1]
|
|
|
}
|
|
|
|
|
|
- errorMessage = ($i18n.t(cleanedDetail) || cleanedDetail) as string
|
|
|
+ // Check if a translation exists for this error
|
|
|
+ const translatedMessage = $i18n.t(cleanedDetail)
|
|
|
+
|
|
|
+ // If we have a valid translation (not the same as the key), return only the translation
|
|
|
+ if (translatedMessage !== cleanedDetail) {
|
|
|
+ return translatedMessage as string
|
|
|
+ }
|
|
|
+
|
|
|
+ // Otherwise return the original error message
|
|
|
+ return cleanedDetail
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- return errorMessage
|
|
|
+ return defaultErrorMessage
|
|
|
}
|
|
|
|
|
|
return {
|