fix some errors
Re-working mongo.InsertError
This commit is contained in:
@@ -34,7 +34,7 @@ func (c CrashReport) GetID() string {
|
||||
func (b *Backend) reportCrash(w http.ResponseWriter, r *http.Request) {
|
||||
hdr, err := b.VerifyHeader(w, r, "crash", false)
|
||||
if hdr == nil {
|
||||
if err == nil {
|
||||
if err != nil {
|
||||
log.Println("request key parsing error:", err)
|
||||
}
|
||||
return
|
||||
@@ -67,7 +67,7 @@ func (b *Backend) reportCrash(w http.ResponseWriter, r *http.Request) {
|
||||
func (b *Backend) deleteCrash(w http.ResponseWriter, r *http.Request) {
|
||||
hdr, err := b.VerifyHeader(w, r, "management", false)
|
||||
if hdr == nil {
|
||||
if err == nil {
|
||||
if err != nil {
|
||||
log.Println("request key parsing error:", err)
|
||||
}
|
||||
return
|
||||
@@ -83,7 +83,7 @@ func (b *Backend) deleteCrash(w http.ResponseWriter, r *http.Request) {
|
||||
func (b *Backend) managementDeleteCrash(w http.ResponseWriter, r *http.Request) {
|
||||
hdr, err := b.VerifyHeader(w, r, "management", true)
|
||||
if hdr == nil {
|
||||
if err == nil {
|
||||
if err != nil {
|
||||
log.Println("request key parsing error:", err)
|
||||
}
|
||||
return
|
||||
@@ -117,7 +117,7 @@ func (b *Backend) actualCrashDelete(w http.ResponseWriter, ap App, crashID strin
|
||||
func (b *Backend) archiveCrash(w http.ResponseWriter, r *http.Request) {
|
||||
hdr, err := b.VerifyHeader(w, r, "management", false)
|
||||
if hdr == nil {
|
||||
if err == nil {
|
||||
if err != nil {
|
||||
log.Println("request key parsing error:", err)
|
||||
}
|
||||
return
|
||||
@@ -135,7 +135,7 @@ func (b *Backend) archiveCrash(w http.ResponseWriter, r *http.Request) {
|
||||
func (b *Backend) managementArchiveCrash(w http.ResponseWriter, r *http.Request) {
|
||||
hdr, err := b.VerifyHeader(w, r, "management", true)
|
||||
if hdr == nil {
|
||||
if err == nil {
|
||||
if err != nil {
|
||||
log.Println("request key parsing error:", err)
|
||||
}
|
||||
return
|
||||
|
||||
@@ -2,10 +2,11 @@ package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/CalebQ42/darkstorm-server/internal/backend"
|
||||
"github.com/google/uuid"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
)
|
||||
@@ -39,32 +40,42 @@ func (m *MongoCrashTable) IsArchived(ind backend.IndividualCrash) bool {
|
||||
|
||||
func (m *MongoCrashTable) InsertCrash(ind backend.IndividualCrash) error {
|
||||
first, _, _ := strings.Cut(ind.Stack, "\n")
|
||||
_, err := m.col.UpdateOne(context.Background(),
|
||||
findRes := m.col.FindOne(context.Background(),
|
||||
bson.M{"error": ind.Error, "firstLine": first, //filter main report
|
||||
"individual.stack": ind.Stack, "individual.platform": ind.Platform}, //filter individual
|
||||
bson.M{"$inc": bson.M{"individual.count": 1}}, //increment count
|
||||
// bson.M{"$inc": bson.M{"individual.count": 1}}, //increment count
|
||||
)
|
||||
if err == mongo.ErrNoDocuments {
|
||||
ind.Count = 1
|
||||
_, err = m.col.UpdateOne(context.Background(),
|
||||
bson.M{"error": ind.Error, "firstLine": first}, //filter
|
||||
bson.M{"$push": bson.M{"individual": ind}}, //Add new individual report
|
||||
)
|
||||
if err == mongo.ErrNoDocuments {
|
||||
var id uuid.UUID
|
||||
id, err = uuid.NewV7()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = m.col.InsertOne(context.Background(),
|
||||
backend.CrashReport{
|
||||
ID: id.String(),
|
||||
Error: ind.Error,
|
||||
FirstLine: first,
|
||||
Individual: []backend.IndividualCrash{ind},
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
return err
|
||||
var out map[string]any
|
||||
findRes.Decode(&out)
|
||||
fmt.Println(out)
|
||||
return errors.New("STUFF")
|
||||
// if err != nil && err != mongo.ErrNoDocuments {
|
||||
// return err
|
||||
// }
|
||||
// if err == mongo.ErrNoDocuments || res.MatchedCount == 0 {
|
||||
// ind.Count = 1
|
||||
// res, err = m.col.UpdateMany(context.Background(),
|
||||
// bson.M{"error": ind.Error, "firstLine": first}, //filter
|
||||
// bson.M{"$push": bson.M{"individual": ind}}, //Add new individual report
|
||||
// )
|
||||
// if err != nil && err != mongo.ErrNoDocuments {
|
||||
// return err
|
||||
// }
|
||||
// if err == mongo.ErrNoDocuments || res.MatchedCount == 0 {
|
||||
// var id uuid.UUID
|
||||
// id, err = uuid.NewV7()
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// _, err = m.col.InsertOne(context.Background(),
|
||||
// backend.CrashReport{
|
||||
// ID: id.String(),
|
||||
// Error: ind.Error,
|
||||
// FirstLine: first,
|
||||
// Individual: []backend.IndividualCrash{ind},
|
||||
// },
|
||||
// )
|
||||
// }
|
||||
// }
|
||||
// return err
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ type countLogReq struct {
|
||||
func (b *Backend) countLog(w http.ResponseWriter, r *http.Request) {
|
||||
hdr, err := b.VerifyHeader(w, r, "count", false)
|
||||
if hdr == nil {
|
||||
if err == nil {
|
||||
if err != nil {
|
||||
log.Println("request key parsing error:", err)
|
||||
}
|
||||
return
|
||||
@@ -101,7 +101,7 @@ func addToCountTable(w http.ResponseWriter, c CountTable, platform string, curDa
|
||||
func (b *Backend) getCount(w http.ResponseWriter, r *http.Request) {
|
||||
hdr, err := b.VerifyHeader(w, r, "management", true)
|
||||
if hdr == nil {
|
||||
if err == nil {
|
||||
if err != nil {
|
||||
log.Println("request key parsing error:", err)
|
||||
}
|
||||
return
|
||||
|
||||
@@ -120,7 +120,7 @@ type createUserReturn struct {
|
||||
func (b *Backend) createUser(w http.ResponseWriter, r *http.Request) {
|
||||
hdr, err := b.VerifyHeader(w, r, "user", false)
|
||||
if hdr == nil {
|
||||
if err == nil {
|
||||
if err != nil {
|
||||
log.Println("request key parsing error:", err)
|
||||
}
|
||||
return
|
||||
@@ -184,7 +184,7 @@ func (b *Backend) createUser(w http.ResponseWriter, r *http.Request) {
|
||||
func (b *Backend) deleteUser(w http.ResponseWriter, r *http.Request) {
|
||||
hdr, err := b.VerifyHeader(w, r, "management", true)
|
||||
if hdr == nil {
|
||||
if err == nil {
|
||||
if err != nil {
|
||||
log.Println("request key parsing error:", err)
|
||||
}
|
||||
return
|
||||
@@ -216,7 +216,7 @@ type loginReturn struct {
|
||||
func (b *Backend) login(w http.ResponseWriter, r *http.Request) {
|
||||
hdr, err := b.VerifyHeader(w, r, "user", false)
|
||||
if hdr == nil {
|
||||
if err == nil {
|
||||
if err != nil {
|
||||
log.Println("request key parsing error:", err)
|
||||
}
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user