Clone the twdehands SDK into mrktplaats and retarget naming and defaults for app.marktplaats.nl while keeping the same request/response bodies and endpoint behavior.
29 lines
666 B
Go
29 lines
666 B
Go
package mrktplaats
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
)
|
|
|
|
// APIError is returned when the API responds with a non-2xx status code.
|
|
type APIError struct {
|
|
StatusCode int
|
|
Body []byte
|
|
}
|
|
|
|
func (e *APIError) Error() string {
|
|
return fmt.Sprintf("mrktplaats: API error %d: %s", e.StatusCode, string(e.Body))
|
|
}
|
|
|
|
// IsNotFound reports whether err is an API 404 response.
|
|
func IsNotFound(err error) bool {
|
|
var apiErr *APIError
|
|
return errors.As(err, &apiErr) && apiErr.StatusCode == 404
|
|
}
|
|
|
|
// IsUnauthorized reports whether err is an API 401 response.
|
|
func IsUnauthorized(err error) bool {
|
|
var apiErr *APIError
|
|
return errors.As(err, &apiErr) && apiErr.StatusCode == 401
|
|
}
|