Skip to content
This repository has been archived by the owner on Dec 22, 2022. It is now read-only.

Commit

Permalink
Creat a Fail-To_Bid error (prebid#636)
Browse files Browse the repository at this point in the history
* Initial implementation

* Makes naming more consistent
  • Loading branch information
hhhjort authored and dbemiller committed Aug 2, 2018
1 parent fc3dddc commit 534f8a8
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
18 changes: 18 additions & 0 deletions errortypes/errortypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const (
TimeoutCode
BadInputCode
BadServerResponseCode
FailedToRequestBidsCode
)

// We should use this code for any Error interface that is not in this package
Expand Down Expand Up @@ -70,6 +71,23 @@ func (err *BadServerResponse) Code() int {
return BadServerResponseCode
}

// FailedToRequestBids is an error to cover the case where an adapter failed to generate any http requests to get bids,
// but did not generate any error messages. This should not happen in practice and will signal that an adapter is poorly
// coded. If there was something wrong with a request such that an adapter could not generate a bid, then it should
// generate an error explaining the deficiency. Otherwise it will be extremely difficult to debug the reason why an
// adapter is not bidding.
type FailedToRequestBids struct {
Message string
}

func (err *FailedToRequestBids) Error() string {
return err.Message
}

func (err *FailedToRequestBids) Code() int {
return FailedToRequestBidsCode
}

// DecodeError provides the error code for an error, as defined above
func DecodeError(err error) int {
if ce, ok := err.(Coder); ok {
Expand Down
4 changes: 4 additions & 0 deletions exchange/bidder.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ func (bidder *bidderAdapter) requestBid(ctx context.Context, request *openrtb.Bi
reqData, errs := bidder.Bidder.MakeRequests(request)

if len(reqData) == 0 {
// If the adapter failed to generate both requests and errors, this is an error.
if len(errs) == 0 {
errs = append(errs, &errortypes.FailedToRequestBids{Message: "The adapter failed to generate any bid requests, but also failed to generate an error explaining why"})
}
return nil, errs
}

Expand Down
2 changes: 2 additions & 0 deletions exchange/exchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,8 @@ func errorsToMetric(errs []error) map[pbsmetrics.AdapterError]struct{} {
ret[pbsmetrics.AdapterErrorBadInput] = s
case errortypes.BadServerResponseCode:
ret[pbsmetrics.AdapterErrorBadServerResponse] = s
case errortypes.FailedToRequestBidsCode:
ret[pbsmetrics.AdapterErrorFailedToRequestBids] = s
default:
ret[pbsmetrics.AdapterErrorUnknown] = s
}
Expand Down
10 changes: 6 additions & 4 deletions pbsmetrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,17 +143,19 @@ func AdapterBids() []AdapterBid {

// Adapter execution status
const (
AdapterErrorBadInput AdapterError = "badinput"
AdapterErrorBadServerResponse AdapterError = "badserverresponse"
AdapterErrorTimeout AdapterError = "timeout"
AdapterErrorUnknown AdapterError = "unknown_error"
AdapterErrorBadInput AdapterError = "badinput"
AdapterErrorBadServerResponse AdapterError = "badserverresponse"
AdapterErrorTimeout AdapterError = "timeout"
AdapterErrorFailedToRequestBids AdapterError = "failedtorequestbid"
AdapterErrorUnknown AdapterError = "unknown_error"
)

func AdapterErrors() []AdapterError {
return []AdapterError{
AdapterErrorBadInput,
AdapterErrorBadServerResponse,
AdapterErrorTimeout,
AdapterErrorFailedToRequestBids,
AdapterErrorUnknown,
}
}
Expand Down

0 comments on commit 534f8a8

Please sign in to comment.