Skip to content

Commit e33b359

Browse files
authored
Merge pull request #29 from 0xsequence/tenant-not-found
Specify "tenant not found" error in ridl file
2 parents 2ca1d56 + fabd8f2 commit e33b359

7 files changed

+35
-17
lines changed

proto/authenticator.gen.go

+6-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

proto/authenticator.ridl

+1
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ struct SessionData
139139
##
140140

141141
error 1000 Unauthorized "Unauthorized access" HTTP 401
142+
error 1001 TenantNotFound "Tenant not found" HTTP 404
142143

143144

144145
##

proto/clients/authenticator.gen.go

+6-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

proto/clients/authenticator.gen.ts

+17-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable */
2-
// sequence-waas-authenticator v0.1.0 c02d115f8e54a1d15199e321aa744883a7c2946e
2+
// sequence-waas-authenticator v0.1.0 a753d63c2d2bbb862ca2c9efb16ba355b19a81aa
33
// --
44
// Code generated by [email protected] with typescript generator. DO NOT EDIT.
55
//
@@ -12,7 +12,7 @@ export const WebRPCVersion = "v1"
1212
export const WebRPCSchemaVersion = "v0.1.0"
1313

1414
// Schema hash generated from your RIDL schema
15-
export const WebRPCSchemaHash = "c02d115f8e54a1d15199e321aa744883a7c2946e"
15+
export const WebRPCSchemaHash = "a753d63c2d2bbb862ca2c9efb16ba355b19a81aa"
1616

1717
//
1818
// Types
@@ -606,6 +606,19 @@ export class UnauthorizedError extends WebrpcError {
606606
}
607607
}
608608

609+
export class TenantNotFoundError extends WebrpcError {
610+
constructor(
611+
name: string = 'TenantNotFound',
612+
code: number = 1001,
613+
message: string = 'Tenant not found',
614+
status: number = 0,
615+
cause?: string
616+
) {
617+
super(name, code, message, status, cause)
618+
Object.setPrototypeOf(this, TenantNotFoundError.prototype)
619+
}
620+
}
621+
609622

610623
export enum errors {
611624
WebrpcEndpoint = 'WebrpcEndpoint',
@@ -620,6 +633,7 @@ export enum errors {
620633
WebrpcStreamLost = 'WebrpcStreamLost',
621634
WebrpcStreamFinished = 'WebrpcStreamFinished',
622635
Unauthorized = 'Unauthorized',
636+
TenantNotFound = 'TenantNotFound',
623637
}
624638

625639
const webrpcErrorByCode: { [code: number]: any } = {
@@ -635,6 +649,7 @@ const webrpcErrorByCode: { [code: number]: any } = {
635649
[-9]: WebrpcStreamLostError,
636650
[-10]: WebrpcStreamFinishedError,
637651
[1000]: UnauthorizedError,
652+
[1001]: TenantNotFoundError,
638653
}
639654

640655
export type Fetch = (input: RequestInfo, init?: RequestInit) => Promise<Response>

proto/proto.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Server
2-
//go:generate go run github.com/webrpc/webrpc/cmd/webrpc-gen -schema=authenticator.ridl -target=golang -pkg=proto -server -client -out=./authenticator.gen.go
2+
//go:generate go run github.com/webrpc/webrpc/cmd/webrpc-gen -schema=authenticator.ridl -target=golang@v0.13.6 -pkg=proto -server -client -out=./authenticator.gen.go
33

44
// Clients
5-
//go:generate go run github.com/webrpc/webrpc/cmd/webrpc-gen -schema=authenticator.ridl -target=golang -pkg=proto -client -out=./clients/authenticator.gen.go
5+
//go:generate go run github.com/webrpc/webrpc/cmd/webrpc-gen -schema=authenticator.ridl -target=golang@v0.13.6 -pkg=proto -client -out=./clients/authenticator.gen.go
66
//go:generate go run github.com/webrpc/webrpc/cmd/webrpc-gen -schema=authenticator.ridl -target=typescript -client -out=./clients/authenticator.gen.ts
77

88
package proto

rpc/admin.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func (s *RPC) GetTenant(ctx context.Context, projectID uint64) (*proto.Tenant, e
2222
return nil, err
2323
}
2424
if tnt == nil {
25-
return nil, fmt.Errorf("tenant not found")
25+
return nil, proto.ErrTenantNotFound
2626
}
2727

2828
tenantData, _, err := crypto.DecryptData[*proto.TenantData](ctx, tnt.EncryptedKey, tnt.Ciphertext, s.Config.KMS.TenantKeys)
@@ -151,7 +151,7 @@ func (s *RPC) UpdateTenant(
151151
return nil, err
152152
}
153153
if !found {
154-
return nil, fmt.Errorf("tenant not found")
154+
return nil, proto.ErrTenantNotFound
155155
}
156156

157157
tntData, _, err := crypto.DecryptData[*proto.TenantData](ctx, tnt.EncryptedKey, tnt.Ciphertext, s.Config.KMS.TenantKeys)

rpc/admin_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func TestRPC_GetTenant(t *testing.T) {
5858

5959
t.Run("MissingTenant", func(t *testing.T) {
6060
tnt, err := c.GetTenant(ctx, 2)
61-
assert.ErrorContains(t, err, "tenant not found")
61+
assert.ErrorIs(t, err, proto.ErrTenantNotFound)
6262
assert.Nil(t, tnt)
6363
})
6464
}

0 commit comments

Comments
 (0)