This commit is contained in:
Illya Marchenko 2024-04-05 17:12:28 +03:00
parent 5178558dfc
commit 77a6a6f54c
Signed by: stuzer05
GPG Key ID: A6ABAAA9268F9F4F
2 changed files with 4 additions and 3 deletions

@ -2,12 +2,13 @@ package main
import (
"encoding/json"
"errors"
"io"
"net/http"
monobank "stuzer.link/monobank-firefly3-bot/monobank/api/webhook/models"
)
func readResponseBody(r *http.Request) (monobank.Transaction, error) {
func readRequestBody(r *http.Request) (monobank.Transaction, error) {
// read body bytes
body, err := io.ReadAll(r.Body)
if err != nil {
@ -18,7 +19,7 @@ func readResponseBody(r *http.Request) (monobank.Transaction, error) {
// check empty body
if len(string(body)) == 0 {
return monobank.Transaction{}, err
return monobank.Transaction{}, errors.New("empty body")
}
// parse body

@ -25,7 +25,7 @@ func handleWebhook(w http.ResponseWriter, r *http.Request) {
// read request
var monobankTransaction monobank.Transaction
monobankTransaction, err = readResponseBody(r)
monobankTransaction, err = readRequestBody(r)
if err != nil {
LogString(err.Error())
w.WriteHeader(http.StatusOK)