1
0
mirror of https://github.com/dstotijn/go-notion.git synced 2025-12-23 23:51:17 +02:00

Simplify APIError.Unwrap, fix missing error message prefixes

This commit is contained in:
David Stotijn
2021-05-14 18:24:56 +02:00
parent d9867284b5
commit fccdde0f5b
2 changed files with 23 additions and 29 deletions

View File

@@ -91,22 +91,22 @@ type DatabaseProperty struct {
func (c *Client) FindDatabaseByID(id string) (db Database, err error) {
req, err := c.newRequest("GET", "/databases/"+id, nil)
if err != nil {
return Database{}, fmt.Errorf("invalid URL: %w", err)
return Database{}, fmt.Errorf("notion: invalid URL: %w", err)
}
res, err := c.httpClient.Do(req)
if err != nil {
return Database{}, fmt.Errorf("failed to make HTTP request: %w", err)
return Database{}, fmt.Errorf("notion: failed to make HTTP request: %w", err)
}
defer res.Body.Close()
if res.StatusCode != 200 {
return Database{}, fmt.Errorf("notion: failed to get database: %w", parseErrorResponse(res))
return Database{}, fmt.Errorf("notion: failed to find database: %w", parseErrorResponse(res))
}
err = json.NewDecoder(res.Body).Decode(&db)
if err != nil {
return Database{}, fmt.Errorf("failed to parse HTTP response: %w", err)
return Database{}, fmt.Errorf("notion: failed to parse HTTP response: %w", err)
}
return db, nil