diff --git a/aliases.go b/aliases.go index 85a555d..528b72f 100644 --- a/aliases.go +++ b/aliases.go @@ -8,6 +8,30 @@ import ( ) type Error = apierror.Error +type ErrorCode = apierror.ErrorCode + +const ErrorCodeCanceled = apierror.ErrorCodeCanceled +const ErrorCodeUnknown = apierror.ErrorCodeUnknown +const ErrorCodeInvalidArgument = apierror.ErrorCodeInvalidArgument +const ErrorCodeDeadlineExceeded = apierror.ErrorCodeDeadlineExceeded +const ErrorCodeNotFound = apierror.ErrorCodeNotFound +const ErrorCodeAlreadyExists = apierror.ErrorCodeAlreadyExists +const ErrorCodePermissionDenied = apierror.ErrorCodePermissionDenied +const ErrorCodeResourceExhausted = apierror.ErrorCodeResourceExhausted +const ErrorCodeFailedPrecondition = apierror.ErrorCodeFailedPrecondition +const ErrorCodeAborted = apierror.ErrorCodeAborted +const ErrorCodeOutOfRange = apierror.ErrorCodeOutOfRange +const ErrorCodeUnimplemented = apierror.ErrorCodeUnimplemented +const ErrorCodeInternal = apierror.ErrorCodeInternal +const ErrorCodeUnavailable = apierror.ErrorCodeUnavailable +const ErrorCodeDataLoss = apierror.ErrorCodeDataLoss +const ErrorCodeUnauthenticated = apierror.ErrorCodeUnauthenticated + +type ArbitraryData = apierror.ArbitraryData +type ArbitraryDataDebug = apierror.ArbitraryDataDebug +type ArbitraryDataType = apierror.ArbitraryDataType +type ArbitraryDataValue = apierror.ArbitraryDataValue +type ArbitraryData = apierror.ArbitraryData // An AutomationTrigger represents a trigger for an automation action. The // `post_environment_start` field indicates that the automation should be triggered diff --git a/internal/apierror/apierror.go b/internal/apierror/apierror.go index fa27a49..641967b 100644 --- a/internal/apierror/apierror.go +++ b/internal/apierror/apierror.go @@ -8,20 +8,36 @@ import ( "net/http/httputil" "github.com/gitpod-io/gitpod-sdk-go/internal/apijson" + "github.com/gitpod-io/gitpod-sdk-go/shared" ) // Error represents an error that originates from the API, i.e. when a request is // made and the API returns a response with a HTTP status code. Other errors are // not wrapped by this SDK. type Error struct { - JSON errorJSON `json:"-"` - StatusCode int - Request *http.Request - Response *http.Response + // The status code, which should be an enum value of + // [google.rpc.Code][google.rpc.Code]. + Code shared.ErrorCode `json:"code"` + // Contains an arbitrary serialized message along with a @type that describes the + // type of the serialized message. + Detail shared.ArbitraryData `json:"detail"` + // A developer-facing error message, which should be in English. Any user-facing + // error message should be localized and sent in the + // [google.rpc.Status.details][google.rpc.Status.details] field, or localized by + // the client. + Message string `json:"message"` + ExtraFields map[string]interface{} `json:"-,extras"` + JSON errorJSON `json:"-"` + StatusCode int + Request *http.Request + Response *http.Response } // errorJSON contains the JSON metadata for the struct [Error] type errorJSON struct { + Code apijson.Field + Detail apijson.Field + Message apijson.Field raw string ExtraFields map[string]apijson.Field }