mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-07-13 09:02:09 -04:00
* introduce configuration settings for TLS insecurity, tracing requests and responses * use more secure implementation when replacing JMAP placeholders in URL templates, path escaping them to avoid injection * add more efficient tracing of HTTP requests and responses between the Groupware backend and the JMAP server, with the possibility of specifying a maximum body size to trace, to avoid blowing up the logs * use more efficient string building for HTTP Authorization headers * change internal API to use streams (io.Reader) instead of reading JSON responses fully into memory before parsing them
118 lines
2.7 KiB
Go
118 lines
2.7 KiB
Go
package jmap
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
const (
|
|
JmapErrorAuthenticationFailed = iota
|
|
JmapErrorInvalidHttpRequest
|
|
JmapErrorServerResponse
|
|
JmapErrorReadingResponseBody
|
|
JmapErrorDecodingResponseBody
|
|
JmapErrorEncodingRequestBody
|
|
JmapErrorCreatingRequest
|
|
JmapErrorSendingRequest
|
|
JmapErrorInvalidSessionResponse
|
|
JmapErrorInvalidJmapRequestPayload
|
|
JmapErrorInvalidJmapResponsePayload
|
|
JmapErrorSetError
|
|
JmapErrorTooManyMethodCalls
|
|
JmapErrorUnspecifiedType
|
|
JmapErrorServerUnavailable
|
|
JmapErrorServerFail
|
|
JmapErrorUnknownMethod
|
|
JmapErrorInvalidArguments
|
|
JmapErrorInvalidResultReference
|
|
JmapErrorForbidden
|
|
JmapErrorAccountNotFound
|
|
JmapErrorAccountNotSupportedByMethod
|
|
JmapErrorAccountReadOnly
|
|
JmapErrorFailedToEstablishWssConnection
|
|
JmapErrorWssConnectionResponseMissingJmapSubprotocol
|
|
JmapErrorWssFailedToSendWebSocketPushEnable
|
|
JmapErrorWssFailedToSendWebSocketPushDisable
|
|
JmapErrorWssFailedToClose
|
|
JmapErrorWssFailedToRetrieveSession
|
|
JmapErrorSocketPushUnsupported
|
|
JmapErrorMissingCreatedObject
|
|
JmapErrorInvalidObjectState
|
|
JmapErrorPatchObjectSerialization
|
|
JmapErrorInvalidProperties
|
|
JmapErrorRequestTracing
|
|
)
|
|
|
|
var (
|
|
errTooManyMethodCalls = errors.New("the amount of methodCalls in the request body would exceed the maximum that is configured in the session")
|
|
)
|
|
|
|
type Error interface {
|
|
Code() int
|
|
error
|
|
}
|
|
|
|
type JmapError struct {
|
|
code int
|
|
err error
|
|
typ string
|
|
description string
|
|
}
|
|
|
|
var _ Error = &JmapError{}
|
|
var _ error = &JmapError{}
|
|
var _ error = JmapError{}
|
|
|
|
func (e JmapError) Code() int {
|
|
return e.code
|
|
}
|
|
func (e JmapError) Unwrap() error {
|
|
return e.err
|
|
}
|
|
func (e JmapError) Error() string {
|
|
if e.err != nil {
|
|
return e.err.Error()
|
|
} else {
|
|
return ""
|
|
}
|
|
}
|
|
func (e JmapError) Type() string {
|
|
return e.typ
|
|
}
|
|
func (e JmapError) Description() string {
|
|
return e.description
|
|
}
|
|
|
|
func jmapError(err error, code int) Error {
|
|
if err != nil {
|
|
return JmapError{code: code, err: err}
|
|
} else {
|
|
return nil
|
|
}
|
|
}
|
|
|
|
func jmapResponseError(code int, err error, typ string, description string) JmapError {
|
|
return JmapError{
|
|
code: code,
|
|
err: err,
|
|
typ: typ,
|
|
description: description,
|
|
}
|
|
}
|
|
|
|
func setErrorError(err SetError, objectType ObjectType) Error {
|
|
var e error
|
|
if len(err.Properties) > 0 {
|
|
e = fmt.Errorf("failed to modify %s due to %s error in properties [%s]: %s", objectType, err.Type, strings.Join(err.Properties, ", "), err.Description)
|
|
} else {
|
|
e = fmt.Errorf("failed to modify %s due to %s error: %s", objectType, err.Type, err.Description)
|
|
}
|
|
code := JmapErrorSetError
|
|
switch err.Type {
|
|
case SetErrorTypeInvalidProperties:
|
|
code = JmapErrorInvalidProperties
|
|
}
|
|
return JmapError{code: code, err: e}
|
|
}
|