1
0
mirror of https://github.com/vwxyzjn/portwarden synced 2025-12-26 03:53:12 +00:00

API-1 # Return basic error messages to the front end

This commit is contained in:
Costa Huang
2018-11-16 17:45:24 -05:00
parent 368f2c7ef7
commit c30f1ed31b
2 changed files with 4 additions and 5 deletions

View File

@@ -189,7 +189,7 @@ func BWLoginGetSessionKey(lc *LoginCredentials) (string, error) {
var stdout bytes.Buffer
cmd.Stdout = &stdout
if err := cmd.Run(); err != nil {
return "", err
return stdout.String(), err
}
sessionKey := stdout.String()
return sessionKey, nil

View File

@@ -14,21 +14,20 @@ import (
func EncryptBackupController(c *gin.Context) {
var bi models.BackupInfo
if err := c.ShouldBindJSON(&bi); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error(), "message": ""})
return
}
spew.Dump(&bi.BitwardenLoginCredentials)
sessionKey, err := portwarden.BWLoginGetSessionKey(&bi.BitwardenLoginCredentials)
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error(), "message": sessionKey})
return
}
fmt.Println(sessionKey)
err = portwarden.CreateBackupFile(bi.FileNamePrefix, bi.Passphrase, sessionKey, models.BackupDefaultSleepMilliseconds)
if err != nil {
panic(err)
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error(), "message": sessionKey})
return
}
}