backend: Don't fail if an hint is already opened
This commit is contained in:
parent
9bc9851b12
commit
41fb5a1cd0
2 changed files with 9 additions and 2 deletions
|
@ -42,7 +42,7 @@ func treatOpeningHint(pathname string, team *fic.Team) {
|
|||
log.Printf("%s [!!!] The team asks to open an hint whereas it doesn't have access to the exercice\n", id)
|
||||
} else if !team.CanSeeHint(hint) {
|
||||
log.Printf("%s [!!!] The team asks to open an hint whereas it doesn't have access to it due to hint dependencies\n", id)
|
||||
} else if err = team.OpenHint(hint); err != nil {
|
||||
} else if err = team.OpenHint(hint); err != nil && !fic.DBIsDuplicateKeyError(err) { // Skip DUPLICATE KEY errors
|
||||
log.Printf("%s [ERR] Unable to open hint: %s\n", id, err)
|
||||
} else {
|
||||
// Write event
|
||||
|
|
|
@ -2,11 +2,13 @@ package fic
|
|||
|
||||
import (
|
||||
"database/sql"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"errors"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/go-sql-driver/mysql"
|
||||
)
|
||||
|
||||
// db stores the connection to the database
|
||||
|
@ -47,6 +49,11 @@ func DSNGenerator() string {
|
|||
return db_user + ":" + db_password + "@" + db_host + "/" + db_db
|
||||
}
|
||||
|
||||
func DBIsDuplicateKeyError(err error) bool {
|
||||
var mysqlErr *mysql.MySQLError
|
||||
return errors.As(err, &mysqlErr) && mysqlErr.Number == 1062
|
||||
}
|
||||
|
||||
// DBInit establishes the connection to the database
|
||||
func DBInit(dsn string) (err error) {
|
||||
if db, err = sql.Open("mysql", dsn+"?parseTime=true&foreign_key_checks=1"); err != nil {
|
||||
|
|
Reference in a new issue