Skip to content

Commit 800314c

Browse files
committed
feat(shared): add standard error codes for API errors
1 parent ff2a3e5 commit 800314c

File tree

4 files changed

+49
-5
lines changed

4 files changed

+49
-5
lines changed

go.mod

+5-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ module github.com/gitpod-io/gitpod-sdk-go
33
go 1.21
44

55
require (
6-
github.com/google/uuid v1.3.0 // indirect
7-
github.com/tidwall/gjson v1.14.4 // indirect
6+
github.com/tidwall/gjson v1.14.4
7+
github.com/tidwall/sjson v1.2.5
8+
)
9+
10+
require (
811
github.com/tidwall/match v1.1.1 // indirect
912
github.com/tidwall/pretty v1.2.1 // indirect
10-
github.com/tidwall/sjson v1.2.5 // indirect
1113
)

go.sum

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
2-
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
31
github.com/tidwall/gjson v1.14.2/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
42
github.com/tidwall/gjson v1.14.4 h1:uo0p8EbA09J7RQaflQ1aBRffTR7xedD2bcIVSYxLnkM=
53
github.com/tidwall/gjson v1.14.4/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=

internal/apierror/error.go

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package apierror
2+
3+
import "github.com/gitpod-io/gitpod-sdk-go/shared"
4+
5+
type ErrorCode = shared.ErrorCode
6+
7+
const ErrorCodeCanceled = shared.ErrorCodeCanceled
8+
const ErrorCodeUnknown = shared.ErrorCodeUnknown
9+
const ErrorCodeInvalidArgument = shared.ErrorCodeInvalidArgument
10+
const ErrorCodeDeadlineExceeded = shared.ErrorCodeDeadlineExceeded
11+
const ErrorCodeNotFound = shared.ErrorCodeNotFound
12+
const ErrorCodeAlreadyExists = shared.ErrorCodeAlreadyExists
13+
const ErrorCodePermissionDenied = shared.ErrorCodePermissionDenied
14+
const ErrorCodeResourceExhausted = shared.ErrorCodeResourceExhausted
15+
const ErrorCodeFailedPrecondition = shared.ErrorCodeFailedPrecondition
16+
const ErrorCodeAborted = shared.ErrorCodeAborted
17+
const ErrorCodeOutOfRange = shared.ErrorCodeOutOfRange
18+
const ErrorCodeUnimplemented = shared.ErrorCodeUnimplemented
19+
const ErrorCodeInternal = shared.ErrorCodeInternal
20+
const ErrorCodeUnavailable = shared.ErrorCodeUnavailable
21+
const ErrorCodeDataLoss = shared.ErrorCodeDataLoss
22+
const ErrorCodeUnauthenticated = shared.ErrorCodeUnauthenticated

shared/error.go

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package shared
2+
3+
type ErrorCode string
4+
5+
const (
6+
ErrorCodeCanceled ErrorCode = "canceled"
7+
ErrorCodeUnknown ErrorCode = "unknown"
8+
ErrorCodeInvalidArgument ErrorCode = "invalid_argument"
9+
ErrorCodeDeadlineExceeded ErrorCode = "deadline_exceeded"
10+
ErrorCodeNotFound ErrorCode = "not_found"
11+
ErrorCodeAlreadyExists ErrorCode = "already_exists"
12+
ErrorCodePermissionDenied ErrorCode = "permission_denied"
13+
ErrorCodeResourceExhausted ErrorCode = "resource_exhausted"
14+
ErrorCodeFailedPrecondition ErrorCode = "failed_precondition"
15+
ErrorCodeAborted ErrorCode = "aborted"
16+
ErrorCodeOutOfRange ErrorCode = "out_of_range"
17+
ErrorCodeUnimplemented ErrorCode = "unimplemented"
18+
ErrorCodeInternal ErrorCode = "internal"
19+
ErrorCodeUnavailable ErrorCode = "unavailable"
20+
ErrorCodeDataLoss ErrorCode = "data_loss"
21+
ErrorCodeUnauthenticated ErrorCode = "unauthenticated"
22+
)

0 commit comments

Comments
 (0)