-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This change removes non-idiomatic gRPC *Reply proto message fields. The client should not receive success/fail values from server methods with a void return type, nor an optional error_message from any server method. This change improves error handling by wrapping an appropriate gRPC Status with a meaningful error description in a StatusRuntimeException, and placing it in the server's response StreamObserver. User error messages are mapped to general purpose gRPC Status codes in a new ApiStatus enum class. (Maybe ApiStatus should be renamed to CoreApiStatus.)
- Loading branch information
Showing
5 changed files
with
164 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* This file is part of Bisq. | ||
* | ||
* Bisq is free software: you can redistribute it and/or modify it | ||
* under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or (at | ||
* your option) any later version. | ||
* | ||
* Bisq is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public | ||
* License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with Bisq. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package bisq.core.grpc; | ||
|
||
import io.grpc.Status; | ||
|
||
/** | ||
* Maps meaningful CoreApi error messages to more general purpose gRPC error Status codes. | ||
* This keeps gRPC api out of CoreApi, and ensures the correct gRPC Status is sent to the | ||
* client. | ||
* | ||
* @see <a href="https://github.com/grpc/grpc/blob/master/doc/statuscodes.md">gRPC Status Codes</a> | ||
*/ | ||
enum ApiStatus { | ||
|
||
INCORRECT_OLD_WALLET_PASSWORD(Status.INVALID_ARGUMENT, "incorrect old password"), | ||
INCORRECT_WALLET_PASSWORD(Status.INVALID_ARGUMENT, "incorrect password"), | ||
|
||
INTERNAL(Status.INTERNAL, "internal server error"), | ||
|
||
OK(Status.OK, null), | ||
|
||
UNKNOWN(Status.UNKNOWN, "unknown"), | ||
|
||
WALLET_ALREADY_LOCKED(Status.FAILED_PRECONDITION, "wallet is already locked"), | ||
|
||
WALLET_ENCRYPTER_NOT_AVAILABLE(Status.FAILED_PRECONDITION, "wallet encrypter is not available"), | ||
|
||
WALLET_IS_ENCRYPTED(Status.FAILED_PRECONDITION, "wallet is encrypted with a password"), | ||
WALLET_IS_ENCRYPTED_WITH_UNLOCK_INSTRUCTION(Status.FAILED_PRECONDITION, | ||
"wallet is encrypted with a password; unlock it with the 'unlock \"password\" timeout' command"), | ||
|
||
WALLET_NOT_ENCRYPTED(Status.FAILED_PRECONDITION, "wallet is not encrypted with a password"), | ||
WALLET_NOT_AVAILABLE(Status.UNAVAILABLE, "wallet is not available"); | ||
|
||
|
||
private final Status grpcStatus; | ||
private final String description; | ||
|
||
ApiStatus(Status grpcStatus, String description) { | ||
this.grpcStatus = grpcStatus; | ||
this.description = description; | ||
} | ||
|
||
Status getGrpcStatus() { | ||
return this.grpcStatus; | ||
} | ||
|
||
String getDescription() { | ||
return this.description; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "ApiStatus{" + | ||
"grpcStatus=" + grpcStatus + | ||
", description='" + description + '\'' + | ||
'}'; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.