Skip to content

Commit beff557

Browse files
authored
fix: guard additional resp from do for nil (#268)
Signed-off-by: Chris Gianelloni <[email protected]>
1 parent c985ba3 commit beff557

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

fcm/message.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
// Copyright 2024 Blink Labs Software
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
115
package fcm
216

317
import (
@@ -92,6 +106,9 @@ func Send(accessToken string, projectId string, msg *Message) error {
92106
if err != nil {
93107
return err
94108
}
109+
if resp == nil {
110+
return fmt.Errorf("failed to send payload to fcm: %s", payload)
111+
}
95112
defer resp.Body.Close()
96113

97114
// Check for errors in the response

output/webhook/webhook.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2023 Blink Labs Software
1+
// Copyright 2024 Blink Labs Software
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -25,8 +25,6 @@ import (
2525
"net/http"
2626
"time"
2727

28-
// cbor "github.com/fxamacker/cbor/v2"
29-
3028
"github.com/blinklabs-io/adder/event"
3129
"github.com/blinklabs-io/adder/input/chainsync"
3230
"github.com/blinklabs-io/adder/internal/logging"
@@ -280,6 +278,9 @@ func (w *WebhookOutput) SendWebhook(e *event.Event) error {
280278
if err != nil {
281279
return fmt.Errorf("%s", err)
282280
}
281+
if resp == nil {
282+
return fmt.Errorf("failed to send payload: %s", data)
283+
}
283284
respBody, err := io.ReadAll(resp.Body)
284285
if err != nil {
285286
return fmt.Errorf("%s", err)

0 commit comments

Comments
 (0)