diff --git a/errors.go b/errors.go index 7b2f286..e87a8cf 100644 --- a/errors.go +++ b/errors.go @@ -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 = ` { diff --git a/loadbalance_content_rewriting.go b/loadbalance_content_rewriting.go index 38718c4..1e39939 100644 --- a/loadbalance_content_rewriting.go +++ b/loadbalance_content_rewriting.go @@ -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 diff --git a/loadbalance_content_rewriting_condition.go b/loadbalance_content_rewriting_condition.go index c670943..4993004 100644 --- a/loadbalance_content_rewriting_condition.go +++ b/loadbalance_content_rewriting_condition.go @@ -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 @@ -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 diff --git a/loadbalance_content_routing.go b/loadbalance_content_routing.go index 150992e..8f98dba 100644 --- a/loadbalance_content_routing.go +++ b/loadbalance_content_routing.go @@ -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 diff --git a/loadbalance_content_routing_condition.go b/loadbalance_content_routing_condition.go index 416cb5e..a546dd4 100644 --- a/loadbalance_content_routing_condition.go +++ b/loadbalance_content_routing_condition.go @@ -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 @@ -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 diff --git a/loadbalance_pool.go b/loadbalance_pool.go index c2f52e9..63f763d 100644 --- a/loadbalance_pool.go +++ b/loadbalance_pool.go @@ -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 diff --git a/loadbalance_pool_member.go b/loadbalance_pool_member.go index 2b8989a..336c7bf 100644 --- a/loadbalance_pool_member.go +++ b/loadbalance_pool_member.go @@ -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 @@ -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 diff --git a/loadbalance_real_server.go b/loadbalance_real_server.go index 82890a8..a8e7465 100644 --- a/loadbalance_real_server.go +++ b/loadbalance_real_server.go @@ -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 diff --git a/loadbalance_virtual_server.go b/loadbalance_virtual_server.go index cd20cb6..fb11322 100644 --- a/loadbalance_virtual_server.go +++ b/loadbalance_virtual_server.go @@ -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 diff --git a/system_certificate_local.go b/system_certificate_local.go index ef173b8..46195de 100644 --- a/system_certificate_local.go +++ b/system_certificate_local.go @@ -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 diff --git a/system_certificate_local_group.go b/system_certificate_local_group.go index 2e88c80..5d71ddc 100644 --- a/system_certificate_local_group.go +++ b/system_certificate_local_group.go @@ -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 diff --git a/system_certificate_local_group_member.go b/system_certificate_local_group_member.go index cf1732c..52d3340 100644 --- a/system_certificate_local_group_member.go +++ b/system_certificate_local_group_member.go @@ -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