Skip to content

Commit 0e57cec

Browse files
committed
Renamed static errors
1 parent 067be92 commit 0e57cec

File tree

3 files changed

+32
-15
lines changed

3 files changed

+32
-15
lines changed

bid.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package openrtb
22

3+
import (
4+
"errors"
5+
)
6+
37
// ID, Impid and Price are required; all other optional.
48
// If the bidder wins the impression, the exchange calls notice URL (nurl)
59
// a) to inform the bidder of the win;
@@ -22,15 +26,22 @@ type Bid struct {
2226
Ext Extensions `json:"ext,omitempty"`
2327
}
2428

29+
// Validation errors
30+
var (
31+
invalidBidId = errors.New("openrtb response: bid is missing ID")
32+
invalidBidImpid = errors.New("openrtb response: bid is missing impression ID")
33+
invalidBidPrice = errors.New("openrtb response: bid is missing price")
34+
)
35+
2536
// Validate Bid required attributes
2637
func (bid *Bid) Valid() (bool, error) {
2738

2839
if bid.Id == nil {
29-
return false, errValidationBidId
40+
return false, invalidBidId
3041
} else if bid.Impid == nil {
31-
return false, errValidationBidImpid
42+
return false, invalidBidImpid
3243
} else if bid.Price == nil {
33-
return false, errValidationBidPrice
44+
return false, invalidBidPrice
3445
}
3546

3647
return true, nil

response.go

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,6 @@ import (
55
"errors"
66
)
77

8-
var (
9-
errValidationResId = errors.New("openrtb response: missing ID")
10-
errValidationResSeatbid = errors.New("openrtb response: missing seatbids")
11-
errValidationSeatbidBid = errors.New("openrtb response: seatbid is missing bids")
12-
errValidationBidId = errors.New("openrtb response: bid is missing ID")
13-
errValidationBidImpid = errors.New("openrtb response: bid is missing impression ID")
14-
errValidationBidPrice = errors.New("openrtb response: bid is missing price")
15-
)
16-
178
// ID and at least one “seatbid” object is required, which contains a bid on at least one impression.
189
// Other attributes are optional since an exchange may establish default values.
1910
// No-Bids on all impressions should be indicated as a HTTP 204 response.
@@ -33,14 +24,20 @@ func (res *Response) JSON() ([]byte, error) {
3324
return json.Marshal(res)
3425
}
3526

27+
// Validation errors
28+
var (
29+
invalidResId = errors.New("openrtb response: missing ID")
30+
invalidResSeatbid = errors.New("openrtb response: missing seatbids")
31+
)
32+
3633
// Validate Response required attributes
3734
// @return [Boolean,Error] true if response,seatbid,bid required attrs present
3835
func (res *Response) Valid() (bool, error) {
3936

4037
if res.Id == nil {
41-
return false, errValidationResId
38+
return false, invalidResId
4239
} else if res.Seatbid == nil || len(res.Seatbid) < 1 {
43-
return false, errValidationResSeatbid
40+
return false, invalidResSeatbid
4441
}
4542

4643
for _, sb := range res.Seatbid {

seatbid.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package openrtb
22

3+
import (
4+
"errors"
5+
)
6+
37
// At least one of Bid is required.
48
// A bid response can contain multiple “seatbid” objects, each on behalf of a different bidder seat.
59
// Seatbid object can contain multiple bids each pertaining to a different impression on behalf of a seat.
@@ -13,11 +17,16 @@ type Seatbid struct {
1317
Ext Extensions `json:"ext,omiempty"`
1418
}
1519

20+
// Validation errors
21+
var (
22+
invalidSeatbidBid = errors.New("openrtb response: seatbid is missing bids")
23+
)
24+
1625
// Validate Seatbid required attributes
1726
func (sb *Seatbid) Valid() (bool, error) {
1827

1928
if sb.Bid == nil || len(sb.Bid) < 1 {
20-
return false, errValidationSeatbidBid
29+
return false, invalidSeatbidBid
2130
}
2231

2332
for _, bid := range sb.Bid {

0 commit comments

Comments
 (0)