Skip to content

Commit

Permalink
add sentinel ErrNotFound (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
pablo-ruth authored Oct 6, 2020
1 parent 4187f99 commit 7c24c61
Show file tree
Hide file tree
Showing 12 changed files with 17 additions and 14 deletions.
3 changes: 3 additions & 0 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ package gofortiadc

import (
"encoding/json"
"errors"
"fmt"
)

var ErrNotFound = errors.New("not found")

// List of ErrCode to ErrMsg from API path "http://myfortiadchost/api/platform/errMsg"
var errMsg = `
{
Expand Down
2 changes: 1 addition & 1 deletion loadbalance_content_rewriting.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (c *Client) LoadbalanceGetContentRewriting(name string) (LoadbalanceContent
}
}

return LoadbalanceContentRewriting{}, fmt.Errorf("content rewriting %s not found", name)
return LoadbalanceContentRewriting{}, fmt.Errorf("content rewriting %s not found: %w", name, ErrNotFound)
}

// LoadbalanceCreateContentRewriting creates a new content rewriting
Expand Down
4 changes: 2 additions & 2 deletions loadbalance_content_rewriting_condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (c *Client) LoadbalanceGetContentRewritingCondition(cr, mkey string) (Loadb
}
}

return LoadbalanceContentRewritingCondition{}, fmt.Errorf("content rewriting condition %s not found", mkey)
return LoadbalanceContentRewritingCondition{}, fmt.Errorf("content rewriting condition %s not found: %w", mkey, ErrNotFound)
}

// LoadbalanceGetContentRewritingConditionID returns a content rewriting condition ID by request
Expand Down Expand Up @@ -140,7 +140,7 @@ func (c *Client) LoadbalanceGetContentRewritingConditionID(cr string, obj Loadba
return cr.Mkey, nil
}

return "", fmt.Errorf("content rewriting condition ID %+v not found", obj)
return "", fmt.Errorf("content rewriting condition ID %+v not found: %w", obj, ErrNotFound)
}

// LoadbalanceCreateContentRewritingCondition creates a new content rewriting condition
Expand Down
2 changes: 1 addition & 1 deletion loadbalance_content_routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (c *Client) LoadbalanceGetContentRouting(name string) (LoadbalanceContentRo
}
}

return LoadbalanceContentRouting{}, fmt.Errorf("content routing %s not found", name)
return LoadbalanceContentRouting{}, fmt.Errorf("content routing %s not found: %w", name, ErrNotFound)
}

// LoadbalanceCreateContentRouting creates a new content routing
Expand Down
4 changes: 2 additions & 2 deletions loadbalance_content_routing_condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (c *Client) LoadbalanceGetContentRoutingCondition(cr, mkey string) (Loadbal
}
}

return LoadbalanceContentRoutingCondition{}, fmt.Errorf("content routing condition %s not found", mkey)
return LoadbalanceContentRoutingCondition{}, fmt.Errorf("content routing condition %s not found: %w", mkey, ErrNotFound)
}

// LoadbalanceGetContentRoutingConditionID returns a content routing condition ID by request
Expand Down Expand Up @@ -136,7 +136,7 @@ func (c *Client) LoadbalanceGetContentRoutingConditionID(cr string, obj Loadbala
return rs.Mkey, nil
}

return "", fmt.Errorf("content routing condition ID %+v not found", obj)
return "", fmt.Errorf("content routing condition ID %+v not found: %w", obj, ErrNotFound)
}

// LoadbalanceCreateContentRoutingCondition creates a new content routing condition
Expand Down
2 changes: 1 addition & 1 deletion loadbalance_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (c *Client) LoadbalanceGetPool(name string) (LoadbalancePool, error) {
}
}

return LoadbalancePool{}, fmt.Errorf("pool %s not found", name)
return LoadbalancePool{}, fmt.Errorf("pool %s not found: %w", name, ErrNotFound)
}

// LoadbalanceCreatePool creates a new real server pool
Expand Down
4 changes: 2 additions & 2 deletions loadbalance_pool_member.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (c *Client) LoadbalanceGetPoolMember(pool, mkey string) (LoadbalancePoolMem
}
}

return LoadbalancePoolMember{}, fmt.Errorf("pool member %s in pool %s not found", mkey, pool)
return LoadbalancePoolMember{}, fmt.Errorf("pool member %s in pool %s not found: %w", mkey, pool, ErrNotFound)
}

// LoadbalanceGetPoolMemberID returns a real server pool member id by name
Expand Down Expand Up @@ -145,7 +145,7 @@ func (c *Client) LoadbalanceGetPoolMemberID(pool, name string) (string, error) {
}
}

return "", fmt.Errorf("pool member %s in pool %s not found", name, pool)
return "", fmt.Errorf("pool member %s in pool %s not found: %w", name, pool, ErrNotFound)
}

// LoadbalanceCreatePoolMember creates a new real server pool member
Expand Down
2 changes: 1 addition & 1 deletion loadbalance_real_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (c *Client) LoadbalanceGetRealServer(name string) (LoadbalanceRealServer, e
}
}

return LoadbalanceRealServer{}, fmt.Errorf("real server %s not found", name)
return LoadbalanceRealServer{}, fmt.Errorf("real server %s not found: %w", name, ErrNotFound)
}

// LoadbalanceCreateRealServer creates a new real server
Expand Down
2 changes: 1 addition & 1 deletion loadbalance_virtual_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func (c *Client) LoadbalanceGetVirtualServer(name string) (LoadbalanceVirtualSer
}
}

return LoadbalanceVirtualServer{}, fmt.Errorf("virtual server %s not found", name)
return LoadbalanceVirtualServer{}, fmt.Errorf("virtual server %s not found: %w", name, ErrNotFound)
}

// LoadbalanceCreateVirtualServer creates a new virtual server
Expand Down
2 changes: 1 addition & 1 deletion system_certificate_local.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (c *Client) SystemGetLocalCertificate(name string) (SystemLocalCertificate,
}
}

return SystemLocalCertificate{}, fmt.Errorf("local certificate %s not found", name)
return SystemLocalCertificate{}, fmt.Errorf("local certificate %s not found: %w", name, ErrNotFound)
}

// SystemCreateLocalCertificate creates a new local certificate
Expand Down
2 changes: 1 addition & 1 deletion system_certificate_local_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (c *Client) SystemGetLocalCertificateGroup(name string) (SystemLocalCertifi
}
}

return SystemLocalCertificateGroup{}, fmt.Errorf("local certificate group %s not found", name)
return SystemLocalCertificateGroup{}, fmt.Errorf("local certificate group %s not found: %w", name, ErrNotFound)
}

// SystemCreateLocalCertificateGroup creates a new local certificate group
Expand Down
2 changes: 1 addition & 1 deletion system_certificate_local_group_member.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (c *Client) SystemGetLocalCertificateGroupMember(group, mkey string) (Syste
}
}

return SystemLocalCertificateGroupMember{}, fmt.Errorf("local certificate group member %s not found", mkey)
return SystemLocalCertificateGroupMember{}, fmt.Errorf("local certificate group member %s not found: %w", mkey, ErrNotFound)
}

// SystemCreateLocalCertificateGroupMember creates a new local certificate group member
Expand Down

0 comments on commit 7c24c61

Please sign in to comment.