-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #133 from heetch/BCN-458-handle-specific-decoding-…
…error-when-schema-registry-unavailable BCN-458 handle specific decoding error when schema registry unavailable
- Loading branch information
Showing
5 changed files
with
103 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package avroregistry | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
// UnavailableError reports an error when the schema registry is unavailable. | ||
type UnavailableError struct { | ||
Cause error | ||
} | ||
|
||
// Error implements the error interface. | ||
func (m *UnavailableError) Error() string { | ||
return fmt.Sprintf("schema registry unavailability caused by: %v", m.Cause) | ||
} | ||
|
||
// Unwrap unwraps and return Cause error. It is needed to properly handle and compare errors. | ||
func (e *UnavailableError) Unwrap() error { | ||
return e.Cause | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package avroregistry_test | ||
|
||
import ( | ||
"errors" | ||
"testing" | ||
|
||
qt "github.com/frankban/quicktest" | ||
|
||
"github.com/heetch/avro/avroregistry" | ||
) | ||
|
||
func TestUnavailableError_Unwrap(t *testing.T) { | ||
c := qt.New(t) | ||
var ErrExpect = errors.New("error") | ||
|
||
err := &avroregistry.UnavailableError{ | ||
Cause: ErrExpect, | ||
} | ||
|
||
c.Assert(errors.Is(err, ErrExpect), qt.IsTrue) | ||
|
||
var newErr *avroregistry.UnavailableError | ||
c.Assert(errors.As(err, &newErr), qt.IsTrue) | ||
} | ||
|
||
func TestUnavailableError_Error(t *testing.T) { | ||
c := qt.New(t) | ||
|
||
err := &avroregistry.UnavailableError{ | ||
Cause: errors.New("ECONNREFUSED"), | ||
} | ||
|
||
c.Assert(err.Error(), qt.Equals, "schema registry unavailability caused by: ECONNREFUSED") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters