M3O SDK Concept

This commit is contained in:
Ben Toogood
2020-11-25 16:06:44 +00:00
parent 7818a050c2
commit 5fa6c1244f
21 changed files with 1293 additions and 524 deletions

39
errors/errors.go Normal file
View File

@@ -0,0 +1,39 @@
package errors
import (
"fmt"
"net/http"
)
// Error returned from a M3O service handler, the status code is used by the M3O API to determine
// the status code of the response.
type Error struct {
// Service which first returned the error
Service string
// StatusCode which indicates the type of error
StatusCode int
// Message provides additional information about an error
Message string
}
func (e *Error) Error() string {
return fmt.Sprintf("%v: %v", http.StatusText(e.StatusCode), e.Message)
}
// BadRequest error indicates that the server cannot or will not process the request due to something
// that is perceived to be a client error (e.g., malformed request syntax)
func BadRequest(format string, a ...interface{}) *Error {
return &Error{
StatusCode: http.StatusBadRequest,
Message: fmt.Sprintf(format, a...),
}
}
// InternalServerError indicates that the server encountered an unexpected condition that prevented
// it from fulfilling the request.
func InternalServerError(format string, a ...interface{}) *Error {
return &Error{
StatusCode: http.StatusInternalServerError,
Message: fmt.Sprintf(format, a...),
}
}