Skip to content

Commit 5ccd790

Browse files
committed
more furniture arranging
1 parent 2e25ff1 commit 5ccd790

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

error-types.md

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,18 @@ With TDD we have the benefit of getting into the mindset of:
7979
8080
What we could do for `DumbGetter` is provide a way for users to use the type system to understand what kind of error has happened.
8181

82-
Let's start with a test.
82+
What if `DumbGetter` could return us something like
83+
84+
```go
85+
type BadStatusError struct {
86+
URL string
87+
Status int
88+
}
89+
```
90+
91+
Rather than a magical string, we have actual _data_ to work with.
92+
93+
Let's change our existing test to reflect this need
8394

8495
```go
8596
t.Run("when you dont get a 200 you get a status error", func(t *testing.T) {
@@ -109,14 +120,9 @@ t.Run("when you dont get a 200 you get a status error", func(t *testing.T) {
109120
})
110121
```
111122

112-
We've added the type `BadStatusError` which implements the error interface.
123+
We'll have to make `BadStatusError` implement the error interface.
113124

114125
```go
115-
type BadStatusError struct {
116-
URL string
117-
Status int
118-
}
119-
120126
func (b BadStatusError) Error() string {
121127
return fmt.Sprintf("did not get 200 from %s, got %d", b.URL, b.Status)
122128
}

0 commit comments

Comments
 (0)