Documentation
¶
Overview ¶
Package errorcode allows to deal with graph error codes
Index ¶
- func FromCS3Status(status *cs3rpc.Status, inerr error, ignore ...cs3rpc.Code) error
- func FromStat(stat *provider.StatResponse, err error, ignore ...cs3rpc.Code) error
- func FromUtilsStatusCodeError(err error, ignore ...cs3rpc.Code) error
- func RenderError(w http.ResponseWriter, r *http.Request, err error)
- type Error
- type ErrorCode
- type ErrorOrigin
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FromCS3Status ¶
FromCS3Status converts a CS3 status code and an error into a corresponding local Error representation.
It takes a *cs3rpc.Status, an error, and a variadic parameter of type cs3rpc.Code. If the error is not nil, it creates an Error object with the error message and a GeneralException code. If the error is nil, it evaluates the provided CS3 status code and returns an equivalent graph Error. If the CS3 status code does not have a direct equivalent within the app, or is ignored, a general purpose Error is returned.
This function is particularly useful when dealing with CS3 responses, and a unified error handling within the application is necessary.
func FromStat ¶
FromStat transforms a *provider.StatResponse object and an error into an Error.
It takes a stat of type *provider.StatResponse, an error, and a variadic parameter of type cs3rpc.Code. It invokes the FromCS3Status function with the StatResponse Status and the ignore codes.
func FromUtilsStatusCodeError ¶
FromUtilsStatusCodeError returns original error if `err` does not match to the statusCodeError type
func RenderError ¶
func RenderError(w http.ResponseWriter, r *http.Request, err error)
RenderError render the Graph Error based on a code or default one
Types ¶
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
Error defines a custom error struct, containing and MS Graph error code and a textual error message
func ToError ¶
ToError checks if the error is of type Error and returns it, the second parameter indicates if the error conversion was successful
func (Error) GetOrigin ¶
func (e Error) GetOrigin() ErrorOrigin
GetOrigin returns the source of the error
func (Error) Render ¶
func (e Error) Render(w http.ResponseWriter, r *http.Request)
Render writes a Graph Error object to the response writer
func (Error) WithOrigin ¶
func (e Error) WithOrigin(o ErrorOrigin) Error
WithOrigin returns a new Error with the provided origin
type ErrorCode ¶
type ErrorCode int
ErrorCode defines code as used in MS Graph - see https://docs.microsoft.com/en-us/graph/errors?context=graph%2Fapi%2F1.0&view=graph-rest-1.0
const ( // AccessDenied defines the error if the caller doesn't have permission to perform the action. AccessDenied ErrorCode = iota // ActivityLimitReached defines the error if the app or user has been throttled. ActivityLimitReached // GeneralException defines the error if an unspecified error has occurred. GeneralException // InvalidAuthenticationToken defines the error if the access token is missing InvalidAuthenticationToken // InvalidRange defines the error if the specified byte range is invalid or unavailable. InvalidRange // InvalidRequest defines the error if the request is malformed or incorrect. InvalidRequest // ItemNotFound defines the error if the resource could not be found. ItemNotFound // MalwareDetected defines the error if malware was detected in the requested resource. MalwareDetected // NameAlreadyExists defines the error if the specified item name already exists. NameAlreadyExists // NotAllowed defines the error if the action is not allowed by the system. NotAllowed // NotSupported defines the error if the request is not supported by the system. NotSupported // ResourceModified defines the error if the resource being updated has changed since the caller last read it, usually an eTag mismatch. ResourceModified // ResyncRequired defines the error if the delta token is no longer valid, and the app must reset the sync state. ResyncRequired // ServiceNotAvailable defines the error if the service is not available. Try the request again after a delay. There may be a Retry-After header. ServiceNotAvailable // SyncStateNotFound defines the error when the sync state generation is not found. The delta token is expired and data must be synchronized again. SyncStateNotFound // QuotaLimitReached the user has reached their quota limit. QuotaLimitReached // Unauthenticated the caller is not authenticated. Unauthenticated // PreconditionFailed the request cannot be made and this error response is sent back PreconditionFailed // ItemIsLocked The item is locked by another process. Try again later. ItemIsLocked )
List taken from https://github.com/microsoft/microsoft-graph-docs-1/blob/main/concepts/errors.md#code-property
func (ErrorCode) CreateOdataError ¶
func (e ErrorCode) CreateOdataError(ctx context.Context, msg string) *libregraph.OdataError
CreateOdataError creates and populates a Graph ErrorCode object
type ErrorOrigin ¶
type ErrorOrigin int
ErrorOrigin gives information about where the error originated
const ( // ErrorOriginUnknown is the default error source // and indicates that the error does not have any information about its origin ErrorOriginUnknown ErrorOrigin = iota // ErrorOriginCS3 indicates that the error originated from a CS3 service ErrorOriginCS3 )