Skip to content

Commit

Permalink
make errors structure lean in makeRequests and remove default assignm…
Browse files Browse the repository at this point in the history
…ent of banner mediaType.
  • Loading branch information
product-trustedstack committed Apr 18, 2024
1 parent 80470f2 commit 40c8bb8
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions adapters/trustedstack/trustedstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@ type adapter struct {
}

func (a *adapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) {
var errs []error

reqJson, err := json.Marshal(request)
if err != nil {
errs = append(errs, err)
return nil, errs
return nil, []error{err}
}

headers := http.Header{}
Expand All @@ -35,7 +33,7 @@ func (a *adapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *adapters.E
Body: reqJson,
Headers: headers,
ImpIDs: openrtb_ext.GetImpIDs(request.Imp),
}}, errs
}}, nil
}

func (a *adapter) MakeBids(internalRequest *openrtb2.BidRequest, externalRequest *adapters.RequestData, response *adapters.ResponseData) (*adapters.BidderResponse, []error) {
Expand Down Expand Up @@ -87,21 +85,25 @@ func getMediaTypeForImp(bid *openrtb2.Bid, imps []openrtb2.Imp) (openrtb_ext.Bid
if err == nil {
return mediaType, nil
}
mediaType = openrtb_ext.BidTypeBanner

for _, imp := range imps {
if imp.ID == bid.ImpID {
switch {
case imp.Banner != nil && imp.Video == nil && imp.Audio == nil && imp.Native == nil:
mediaType = openrtb_ext.BidTypeBanner
case imp.Banner == nil && imp.Video != nil && imp.Audio == nil && imp.Native == nil:
mediaType = openrtb_ext.BidTypeVideo
case imp.Banner == nil && imp.Video == nil && imp.Audio != nil && imp.Native == nil:
mediaType = openrtb_ext.BidTypeAudio
case imp.Banner == nil && imp.Video == nil && imp.Audio == nil && imp.Native != nil:
mediaType = openrtb_ext.BidTypeNative
}
return mediaType, nil
}
}

if mediaType != "" {
return mediaType, nil
}
return "", &errortypes.BadInput{
Message: fmt.Sprintf("Failed to find impression \"%s\"", bid.ImpID),
}
Expand Down

0 comments on commit 40c8bb8

Please sign in to comment.