Don Newton | 379ae25 | 2019-04-01 12:17:06 -0400 | [diff] [blame^] | 1 | // Copyright (C) MongoDB, Inc. 2017-present. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 4 | // not use this file except in compliance with the License. You may obtain |
| 5 | // a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | |
| 7 | package connection |
| 8 | |
| 9 | import "fmt" |
| 10 | |
| 11 | // Error represents a connection error. |
| 12 | type Error struct { |
| 13 | ConnectionID string |
| 14 | Wrapped error |
| 15 | |
| 16 | message string |
| 17 | } |
| 18 | |
| 19 | // Error implements the error interface. |
| 20 | func (e Error) Error() string { |
| 21 | if e.Wrapped != nil { |
| 22 | return fmt.Sprintf("connection(%s) %s: %s", e.ConnectionID, e.message, e.Wrapped.Error()) |
| 23 | } |
| 24 | return fmt.Sprintf("connection(%s) %s", e.ConnectionID, e.message) |
| 25 | } |
| 26 | |
| 27 | // NetworkError represents an error that occurred while reading from or writing |
| 28 | // to a network socket. |
| 29 | type NetworkError struct { |
| 30 | ConnectionID string |
| 31 | Wrapped error |
| 32 | } |
| 33 | |
| 34 | func (ne NetworkError) Error() string { |
| 35 | return fmt.Sprintf("connection(%s): %s", ne.ConnectionID, ne.Wrapped.Error()) |
| 36 | } |
| 37 | |
| 38 | // PoolError is an error returned from a Pool method. |
| 39 | type PoolError string |
| 40 | |
| 41 | func (pe PoolError) Error() string { return string(pe) } |