Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -12,6 +12,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
mssql "github.com/microsoft/go-mssqldb"
|
||||
)
|
||||
|
||||
// ======================================================
|
||||
@@ -136,8 +137,7 @@ func OrderProductionValidateRoute(mssql *sql.DB) http.Handler {
|
||||
|
||||
missing, err := buildMissingVariants(mssql, id, payload.Lines)
|
||||
if err != nil {
|
||||
log.Printf("❌ validate error: %v", err)
|
||||
http.Error(w, "Veritabani hatasi", http.StatusInternalServerError)
|
||||
writeDBError(w, http.StatusInternalServerError, "validate_missing_variants", id, "", len(payload.Lines), err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -176,8 +176,7 @@ func OrderProductionApplyRoute(mssql *sql.DB) http.Handler {
|
||||
|
||||
missing, err := buildMissingVariants(mssql, id, payload.Lines)
|
||||
if err != nil {
|
||||
log.Printf("❌ apply validate error: %v", err)
|
||||
http.Error(w, "Veritabani hatasi", http.StatusInternalServerError)
|
||||
writeDBError(w, http.StatusInternalServerError, "apply_validate_missing_variants", id, "", len(payload.Lines), err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -202,7 +201,7 @@ func OrderProductionApplyRoute(mssql *sql.DB) http.Handler {
|
||||
|
||||
tx, err := mssql.Begin()
|
||||
if err != nil {
|
||||
http.Error(w, "Veritabani hatasi", http.StatusInternalServerError)
|
||||
writeDBError(w, http.StatusInternalServerError, "begin_tx", id, username, len(payload.Lines), err)
|
||||
return
|
||||
}
|
||||
defer tx.Rollback()
|
||||
@@ -211,22 +210,19 @@ func OrderProductionApplyRoute(mssql *sql.DB) http.Handler {
|
||||
if payload.InsertMissing {
|
||||
inserted, err = queries.InsertMissingVariantsTx(tx, missing, username)
|
||||
if err != nil {
|
||||
log.Printf("❌ insert missing error: %v", err)
|
||||
http.Error(w, "Veritabani hatasi", http.StatusInternalServerError)
|
||||
writeDBError(w, http.StatusInternalServerError, "insert_missing_variants", id, username, len(missing), err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
updated, err := queries.UpdateOrderLinesTx(tx, id, payload.Lines, username)
|
||||
if err != nil {
|
||||
log.Printf("❌ update order lines error: %v", err)
|
||||
http.Error(w, "Veritabani hatasi", http.StatusInternalServerError)
|
||||
writeDBError(w, http.StatusInternalServerError, "update_order_lines", id, username, len(payload.Lines), err)
|
||||
return
|
||||
}
|
||||
|
||||
if err := tx.Commit(); err != nil {
|
||||
log.Printf("❌ commit error: %v", err)
|
||||
http.Error(w, "Veritabani hatasi", http.StatusInternalServerError)
|
||||
writeDBError(w, http.StatusInternalServerError, "commit_tx", id, username, len(payload.Lines), err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -289,3 +285,26 @@ func validateUpdateLines(lines []models.OrderProductionUpdateLine) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func writeDBError(w http.ResponseWriter, status int, step string, orderHeaderID string, username string, lineCount int, err error) {
|
||||
var sqlErr mssql.Error
|
||||
if errors.As(err, &sqlErr) {
|
||||
log.Printf(
|
||||
"❌ SQL error step=%s orderHeaderID=%s user=%s lineCount=%d number=%d state=%d class=%d server=%s proc=%s line=%d message=%s",
|
||||
step, orderHeaderID, username, lineCount,
|
||||
sqlErr.Number, sqlErr.State, sqlErr.Class, sqlErr.ServerName, sqlErr.ProcName, sqlErr.LineNo, sqlErr.Message,
|
||||
)
|
||||
} else {
|
||||
log.Printf(
|
||||
"❌ DB error step=%s orderHeaderID=%s user=%s lineCount=%d err=%v",
|
||||
step, orderHeaderID, username, lineCount, err,
|
||||
)
|
||||
}
|
||||
|
||||
w.WriteHeader(status)
|
||||
_ = json.NewEncoder(w).Encode(map[string]any{
|
||||
"message": "Veritabani hatasi",
|
||||
"step": step,
|
||||
"detail": err.Error(),
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user