Skip to content

Commit 4768ba4

Browse files
arg-ttd-exception-for-malformed-endpoint
1 parent d07733a commit 4768ba4

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

adapters/thetradedesk/thetradedesk.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ import (
1717
"github.com/prebid/openrtb/v20/openrtb2"
1818
)
1919

20-
//const PREBID_INTEGRATION_TYPE = "1"
21-
2220
type adapter struct {
2321
bidderEndpointTemplate string
2422
defaultEndpoint string
@@ -87,13 +85,12 @@ func (a *adapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *adapters.E
8785

8886
bidderEndpoint, err := a.buildEndpointURL(supplySourceId)
8987
if err != nil {
90-
return nil, []error{errors.New("Failed to build endpoint URL")}
88+
return nil, []error{err}
9189
}
9290

9391
headers := http.Header{}
9492
headers.Add("Content-Type", "application/json;charset=utf-8")
9593
headers.Add("Accept", "application/json")
96-
//headers.Add("x-integration-type", PREBID_INTEGRATION_TYPE) this will be parsed and added conditionally later
9794
return []*adapters.RequestData{{
9895
Method: "POST",
9996
Uri: bidderEndpoint,
@@ -105,6 +102,9 @@ func (a *adapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *adapters.E
105102

106103
func (a *adapter) buildEndpointURL(supplySourceId string) (string, error) {
107104
if supplySourceId == "" {
105+
if a.defaultEndpoint == "" {
106+
return "", errors.New("Either supplySourceId or a default endpoint must be provided")
107+
}
108108
return a.defaultEndpoint, nil
109109
}
110110

adapters/thetradedesk/thetradedesk_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package thetradedesk
22

33
import (
44
"encoding/json"
5+
"errors"
56
"github.com/prebid/prebid-server/v3/adapters/adapterstest"
67
"net/http"
78
"testing"
@@ -425,7 +426,7 @@ func TestTheTradeDeskAdapter_BuildEndpoint(t *testing.T) {
425426
supplySourceId: "",
426427
defaultEndpoint: "",
427428
expectedEndpoint: "",
428-
wantErr: nil,
429+
wantErr: []error{errors.New("Either supplySourceId or a default endpoint must be provided")},
429430
},
430431
}
431432

@@ -442,6 +443,9 @@ func TestTheTradeDeskAdapter_BuildEndpoint(t *testing.T) {
442443
finalEndpoint, err := a.buildEndpointURL(tt.supplySourceId)
443444
if tt.wantErr != nil {
444445
assert.NotNil(t, err)
446+
assert.Equal(t, tt.wantErr[0].Error(), err.Error())
447+
} else {
448+
assert.Nil(t, err)
445449
}
446450
assert.Equal(t, tt.expectedEndpoint, finalEndpoint)
447451
})

0 commit comments

Comments
 (0)