Skip to content

Commit

Permalink
feat(submission-url): Allow submit.backtrace.io submission url (#22)
Browse files Browse the repository at this point in the history
Allow submit.backtrace.io submission URL.

Now supports two types of url:
New: endpoint=https://submit.backtrace.io/fake-company/fake-token/json
Old but still supported: endpoint=https://myurl.in.backtrace.io,
token=64charactersfortoken
  • Loading branch information
MateuszKepczynskiSauce authored Nov 28, 2024
1 parent 251c7db commit 0352f18
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,14 @@ func checkOptions() bool {
}
panic("must set bt.Options.Endpoint")
}
if len(Options.Token) == 0 {
if !Options.DebugBacktrace {
return false

if !strings.HasPrefix(Options.Endpoint, "https://submit.backtrace.io") {
if len(Options.Token) == 0 {
if !Options.DebugBacktrace {
return false
}
panic("must set bt.Options.Token")
}
panic("must set bt.Options.Token")
}
return true
}
Expand Down Expand Up @@ -256,7 +259,12 @@ func processAndSend(payload *reportPayload) {
report["sourceCode"] = sourceCode
report["classifiers"] = []string{payload.classifier}

fullUrl := fmt.Sprintf("%s/post?format=json&token=%s", Options.Endpoint, url.QueryEscape(Options.Token))
fullUrl := Options.Endpoint

if len(Options.Token) != 0 { // if token is set that means its old URL.
fullUrl = fmt.Sprintf("%s/post?format=json&token=%s", Options.Endpoint, url.QueryEscape(Options.Token))
}

if Options.DebugBacktrace {
fmt.Fprintf(os.Stderr, "POST %s\n", fullUrl)
var err error
Expand Down

0 comments on commit 0352f18

Please sign in to comment.