Skip to content

Commit

Permalink
feat: add option for ignoring missing mapped types (#34)
Browse files Browse the repository at this point in the history
feat: silently drop messages with missing mapped types
  • Loading branch information
argoyle authored Dec 18, 2023
1 parent a0b84aa commit 9e2bfd9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
2 changes: 1 addition & 1 deletion connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func (c *Connection) TypeMappingHandler(handler HandlerFunc) HandlerFunc {
routingKey := headers["routing-key"].(string)
typ, exists := c.keyToType[routingKey]
if !exists {
return nil, fmt.Errorf("no mapped type found for routing key '%s'", routingKey)
return nil, nil
}
body := []byte(*msg.(*json.RawMessage))
message, err := c.parseMessage(body, typ)
Expand Down
8 changes: 3 additions & 5 deletions connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ func TestConnection_TypeMappingHandler(t *testing.T) {
wantErr assert.ErrorAssertionFunc
}{
{
name: "no mapped type",
name: "no mapped type, ignored",
fields: fields{},
args: args{
msg: []byte(`{"a":true}`),
Expand All @@ -574,10 +574,8 @@ func TestConnection_TypeMappingHandler(t *testing.T) {
}
},
},
want: nil,
wantErr: func(t assert.TestingT, err error, i ...interface{}) bool {
return assert.EqualError(t, err, "no mapped type found for routing key 'unknown'")
},
want: nil,
wantErr: assert.NoError,
},
{
name: "parse error",
Expand Down

0 comments on commit 9e2bfd9

Please sign in to comment.