Traduire messages d'erreurs en français

Il serait intéressant d'ajouter un méchanisme d'internationalisation des
chaines.
This commit is contained in:
Victor Lacasse-Beaudoin 2023-06-10 00:07:51 -04:00
parent 660d8826e2
commit bacd4d737e
3 changed files with 20 additions and 20 deletions

View file

@ -47,7 +47,7 @@ func (a *ApiClient) Call(method, route string, requestBody io.Reader, useKey boo
if useKey { if useKey {
if a.Key == "" { if a.Key == "" {
return response, fmt.Errorf("Call to API required a key but none was provided. See --help for instructions on providing an API key.") return response, fmt.Errorf("L'appel au serveur API requiert une clé, mais aucune n'était donnée. Voir --help pour les instructions sur comment fournir une clé API.")
} }
request.Header.Add("Authorization", fmt.Sprintf("Bearer %s", a.Key)) request.Header.Add("Authorization", fmt.Sprintf("Bearer %s", a.Key))
@ -87,7 +87,7 @@ func (a *ApiClient) GetHealth() (string, error) {
} }
if response.Message == "" { if response.Message == "" {
return response.Message, errors.New("Could not confirm that API server is up, no response message") return response.Message, errors.New("Impossible de confirmer l'état du serveur API.")
} }
return response.Message, nil return response.Message, nil

View file

@ -87,7 +87,7 @@ func (d *DataClient) InsertTransactions(transactions []models.Transaction) ([]mo
// Check values // Check values
if transaction.MembreID == "" { if transaction.MembreID == "" {
tx.Rollback() tx.Rollback()
return rowsInserted, errors.New("Cannot insert transaction with no membre_id") return rowsInserted, errors.New("Impossible d'insérer une transaction sans membre_id")
} }
rows, err := tx.NamedQuery("INSERT INTO transactions (membre_id, given_at, is_perpetual) VALUES (:membre_id, current_timestamp, :is_perpetual) RETURNING id, membre_id, is_perpetual;", &transaction) rows, err := tx.NamedQuery("INSERT INTO transactions (membre_id, given_at, is_perpetual) VALUES (:membre_id, current_timestamp, :is_perpetual) RETURNING id, membre_id, is_perpetual;", &transaction)
@ -126,7 +126,7 @@ func (d *DataClient) GetTransaction(membreID string, is_perpetual bool) (models.
} }
if transaction.ID == "" { if transaction.ID == "" {
return transaction, fmt.Errorf("No transaction found") return transaction, fmt.Errorf("Aucune transaction trouvée")
} }
return transaction, nil return transaction, nil

View file

@ -19,7 +19,7 @@ func GetTransactions(c echo.Context) error {
client, err := data.NewDataClientFromViper() client, err := data.NewDataClientFromViper()
if err != nil { if err != nil {
response.Message = fmt.Sprintf("Error during data.NewDataClientFromViper(): %s", err) response.Message = fmt.Sprintf("Erreur pendant data.NewDataClientFromViper(): %s", err)
return c.JSON(statusCode, response) return c.JSON(statusCode, response)
} }
@ -28,19 +28,19 @@ func GetTransactions(c echo.Context) error {
transactions, err := client.ListTransactions() transactions, err := client.ListTransactions()
response.Data.Transactions = transactions response.Data.Transactions = transactions
if err != nil { if err != nil {
response.Message = fmt.Sprintf("Error during client.ListTransactions(): %s", err) response.Message = fmt.Sprintf("Erreur pendant client.ListTransactions(): %s", err)
return c.JSON(statusCode, response) return c.JSON(statusCode, response)
} }
if len(transactions) == 0 { if len(transactions) == 0 {
response.Message = "No transactions found" response.Message = "Aucune transaction trouvée"
statusCode = http.StatusNotFound statusCode = http.StatusNotFound
return c.JSON(statusCode, response) return c.JSON(statusCode, response)
} }
response.Message = "List successful" response.Message = "Liste complétée"
statusCode = http.StatusOK statusCode = http.StatusOK
return c.JSON(statusCode, response) return c.JSON(statusCode, response)
@ -55,21 +55,21 @@ func PostTransactions(c echo.Context) error {
if err := c.Bind(&transactions); err != nil { if err := c.Bind(&transactions); err != nil {
statusCode = http.StatusBadRequest statusCode = http.StatusBadRequest
response.Message = fmt.Sprintf("Error during c.Bind(): %s", err) response.Message = fmt.Sprintf("Erreur pendant c.Bind(): %s", err)
return c.JSON(statusCode, response) return c.JSON(statusCode, response)
} }
client, err := data.NewDataClientFromViper() client, err := data.NewDataClientFromViper()
if err != nil { if err != nil {
response.Message = fmt.Sprintf("Error during data.NewDataClientFromViper(): %s", err) response.Message = fmt.Sprintf("Erreur pendant data.NewDataClientFromViper(): %s", err)
return c.JSON(statusCode, response) return c.JSON(statusCode, response)
} }
defer client.DB.Close() defer client.DB.Close()
if len(transactions) == 0 { if len(transactions) == 0 {
response.Message = fmt.Sprintf("Nothing to do") response.Message = fmt.Sprintf("Rien à faire")
statusCode = http.StatusOK statusCode = http.StatusOK
return c.JSON(statusCode, response) return c.JSON(statusCode, response)
@ -91,20 +91,20 @@ func PostTransactions(c echo.Context) error {
// Check if membre_id exists according to bottin // Check if membre_id exists according to bottin
for _, transaction := range transactions { for _, transaction := range transactions {
if transaction.MembreID == "" { if transaction.MembreID == "" {
response.Message = fmt.Sprintf("Cannot insert transaction without a membre_id") response.Message = fmt.Sprintf("Impossible d'insérer une transaction sans membre_id (numéro étudiant)")
statusCode = http.StatusBadRequest statusCode = http.StatusBadRequest
return c.JSON(statusCode, response) return c.JSON(statusCode, response)
} }
membre, err := bottinApiClient.GetMembre(transaction.MembreID) membre, err := bottinApiClient.GetMembre(transaction.MembreID)
if err != nil { if err != nil {
response.Message = fmt.Sprintf("Error during bottinApiClient.GetMembre(): %s", err) response.Message = fmt.Sprintf("Erreur pendant bottinApiClient.GetMembre(): %s", err)
return c.JSON(statusCode, response) return c.JSON(statusCode, response)
} }
if membre.ID == "" { if membre.ID == "" {
response.Message = fmt.Sprintf("Cannot insert transaction for non-existent membre %s", membre.ID) response.Message = fmt.Sprintf("Aucun membre avec numéro étudiant '%s' dans le bottin de l'AGECEM", membre.ID)
statusCode = http.StatusNotFound statusCode = http.StatusNotFound
return c.JSON(statusCode, response) return c.JSON(statusCode, response)
@ -118,17 +118,17 @@ func PostTransactions(c echo.Context) error {
transaction, err := client.GetTransaction(transaction.MembreID, transaction.IsPerpetual) transaction, err := client.GetTransaction(transaction.MembreID, transaction.IsPerpetual)
if err != nil { if err != nil {
if err.Error() != "sql: no rows in result set" { if err.Error() != "sql: no rows in result set" {
response.Message = fmt.Sprintf("Error during client.GetTransaction(): %s", err) response.Message = fmt.Sprintf("Erreur pendant client.GetTransaction(): %s", err)
} }
} }
if transaction.ID != "" { if transaction.ID != "" {
agendaType := "non-perpetual" agendaType := "non-perpétuel"
if transaction.IsPerpetual { if transaction.IsPerpetual {
agendaType = "perpetual" agendaType = "perpétuel"
} }
response.Message = fmt.Sprintf("Membre %s already received %s", transaction.MembreID, agendaType) response.Message = fmt.Sprintf("Membre %s a déjà son agenda %s", transaction.MembreID, agendaType)
statusCode = http.StatusBadRequest statusCode = http.StatusBadRequest
@ -139,13 +139,13 @@ func PostTransactions(c echo.Context) error {
insertedTransactions, err := client.InsertTransactions(transactions) insertedTransactions, err := client.InsertTransactions(transactions)
response.Data.Transactions = insertedTransactions response.Data.Transactions = insertedTransactions
if err != nil { if err != nil {
response.Message = fmt.Sprintf("Error during client.InsertTransactions(): %s", err) response.Message = fmt.Sprintf("Erreur pendant client.InsertTransactions(): %s", err)
return c.JSON(statusCode, response) return c.JSON(statusCode, response)
} }
statusCode = http.StatusCreated statusCode = http.StatusCreated
response.Message = "Insert successful" response.Message = "Insertion complétée"
return c.JSON(statusCode, response) return c.JSON(statusCode, response)
} }