Skip to content

Commit

Permalink
add kratos errors
Browse files Browse the repository at this point in the history
  • Loading branch information
MuZhou233 committed Sep 26, 2022
1 parent 090913f commit 4afac42
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 0 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ install-plugins:
GO111MODULE=off go get github.com/gogo/protobuf/protoc-gen-gofast
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
go install github.com/go-kratos/kratos/cmd/protoc-gen-go-errors/v2@latest
npm install
cargo install protoc-gen-prost-crate

Expand Down
4 changes: 4 additions & 0 deletions buf.gen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ plugins:
out: pkg
opt:
- paths=source_relative
- name: go-errors
out: pkg
opt:
- paths=source_relative

#JS
- remote: buf.build/protocolbuffers/plugins/js:v3.19.1-1
Expand Down
3 changes: 3 additions & 0 deletions proto/buf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ breaking:
lint:
use:
- DEFAULT
ignore_only:
PACKAGE_VERSION_SUFFIX:
- errors/errors.proto
25 changes: 25 additions & 0 deletions proto/errors/errors.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
syntax = "proto3";

package errors;

import "google/protobuf/descriptor.proto";

option go_package = "github.com/go-kratos/kratos/v2/errors;errors";
option java_multiple_files = true;
option java_package = "com.github.kratos.errors";
option objc_class_prefix = "KratosErrors";

message Error {
int32 code = 1;
string reason = 2;
string message = 3;
map<string, string> metadata = 4;
}

extend google.protobuf.EnumOptions {
int32 default_code = 1108;
}

extend google.protobuf.EnumValueOptions {
int32 code = 1109;
}
22 changes: 22 additions & 0 deletions proto/librarian/sephirah/v1/errors.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
syntax = "proto3";

package librarian.sephirah.v1;

import "errors/errors.proto";

option csharp_namespace = "TuiHub.Protos.Librarian.Sephirah.V1";
option go_package = "github.com/tuihub/librarian/sephirah;v1";

enum ErrorReason {
option (errors.default_code) = 500;

ERROR_REASON_UNSPECIFIED = 0 [(errors.code) = 500];

ERROR_REASON_BAD_REQUEST = 1 [(errors.code) = 400];
ERROR_REASON_UNAUTHORIZED = 2 [(errors.code) = 401];
ERROR_REASON_FORBIDDEN = 3 [(errors.code) = 403];
ERROR_REASON_NOT_FOUND = 4 [(errors.code) = 404];
ERROR_REASON_METHOD_NOT_ALLOWED = 5 [(errors.code) = 405];
ERROR_REASON_NOT_IMPLEMENTED = 6 [(errors.code) = 501];
ERROR_REASON_BAD_GATEWAY = 7 [(errors.code) = 502];
}

0 comments on commit 4afac42

Please sign in to comment.