Commit 176fae41 authored by Andreas Wagner's avatar Andreas Wagner
Browse files

Fix response codes and catch some upstream errors.

parent c0e81c35
......@@ -396,6 +396,10 @@ func ProcessHook(hookType string, r io.ReadSeeker, conf *tei2zenodo.Config) (map
}
log.Printf(" Parsed push hook with %d commits and %d files: %s", len(payload.Commits), len(files), strings.Join(fls, ", "))
}
if len(files) == 0 {
log.Warnf("No files to process")
return nil, tei2zenodo.NewError("warnInapplicable", fmt.Sprintf("no files to process"), 204, nil)
}
return files, nil
}
case "ping":
......@@ -623,11 +627,7 @@ func PutFile(myDeposit *tei2zenodo.Deposit, conf *tei2zenodo.Config, c *gin.Cont
// 6. Done, reporting...
// log.Printf("Response code %d, content: %s", resp.StatusCode, content)
if conf.Verbose {
log.Printf(" Success (%s Bytes). Commit SHA: %s", newEntry.GetSize(), *newCommit.SHA)
} else {
log.Printf(" Success.")
}
log.Printf(" Success. Commit SHA: %s", myDeposit.CommitSHA)
return myDeposit.CommitSHA, nil
......
......@@ -168,7 +168,7 @@ func SetupRoutes(conf tei2zenodo.Config) *gin.Engine {
switch PHErr.Typ {
case "warnInapplicable":
{
log.Errorf("webhook inapplicable: %v", PHErr)
log.Warnf("webhook inapplicable: %v", PHErr)
c.Status(http.StatusNoContent) // "processed hook successfully (nothing to do)"
return
}
......@@ -244,14 +244,16 @@ func SetupRoutes(conf tei2zenodo.Config) *gin.Engine {
return
}
log.Printf(" Successfully processed file %s (DOI %s, github SHA %s).", myDeposit.Filename, myDeposit.DepositDOI, myDeposit.DepositDOI)
SHAs = append(SHAs, myDeposit.CommitSHA)
log.Printf(" Successfully processed file %s (DOI %s, github SHA %s).", myDeposit.Filename, myDeposit.DepositDOI, myDeposit.CommitSHA)
DOIs = append(DOIs, myDeposit.DOIURL)
SHAs = append(SHAs, "https://api.github.com/repos/"+conf.Git.Repo+"/commits/"+myDeposit.CommitSHA)
}
log.Printf("====== All done ======")
c.Header("Location", strings.Join(DOIs, ";"))
c.JSON(http.StatusCreated, gin.H{"doi": DOIs, "sha": SHAs})
if len(DOIs) == 1 {
c.Header("Location", DOIs[0])
}
c.JSON(http.StatusCreated, gin.H{"doi": DOIs, "commits": SHAs})
})
}
}
......
......@@ -96,6 +96,7 @@ func ProcessFile(r io.ReadSeeker, doi string, md *tei2zenodo.ZMetadata, myDeposi
return tei2zenodo.NewError("errZProcessing", fmt.Sprintf("error uploading to zenodo, sending POST request: %s", PFErr), 500, PFErr)
}
myDeposit.ZenodoURL = url
myDeposit.DOIURL = "https://doi.org/" + md.DOI
log.Printf("--- Add metadata to zenodo ---")
PMErr := putMetadata(myDeposit, md, conf)
......@@ -253,9 +254,16 @@ func updateDeposit(d *tei2zenodo.Deposit, md *tei2zenodo.ZMetadata, c *tei2zenod
log.Errorf("Problem reading GET response: %v ...", err)
return "", fmt.Errorf("problem reading GET response: %s", err)
}
if strconv.Itoa(resp.StatusCode)[:1] != "2" {
log.Errorf("Problem reported by resolver: %d %v. %s ...", resp.StatusCode, err, content)
return "", fmt.Errorf("problem reported by resolver: %d %v. %s", resp.StatusCode, err, content)
switch strconv.Itoa(resp.StatusCode)[:1] {
case "4", "5":
{
if resp.StatusCode == http.StatusGone { // 410 Gone
log.Warnf("PID %s has been deleted, create new one from scratch", d.OldDOI)
return createNewDOI(md, c)
}
log.Errorf("Problem reported by resolver: %d %v. %s ...", resp.StatusCode, err, content)
return "", fmt.Errorf("problem reported by resolver: %d %v. %s", resp.StatusCode, err, content)
}
}
// Parse response
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment