Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Translate errors from HTTP statuses #362

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

v0idpwn
Copy link
Contributor

@v0idpwn v0idpwn commented May 3, 2024

This is inspired in how GRPC go approaches HTTP errors when performing GRPC requests.

Error translation is useful in different situations. For example, AWS load balancer replies with a 504 when there are no live instances. There, a unavailable error is much more fitting than internal.

For go translation table: https://github.com/grpc/grpc-go/blob/273fe145d03df516018cf4642e6987e027ffc0f5/internal/transport/http_util.go#L68

This is inspired in how GRPC go approaches HTTP errors when performing
GRPC requests.

This provides meaningful errors in different situations. For example, AWS
load balancer replies with a 504 when there are no live instances.
There, a `unavailable` error is much more fitting than `internal`.
@v0idpwn
Copy link
Contributor Author

v0idpwn commented May 3, 2024

I didn't find where these errors are handled in Mint (if they are), so I didn't touch it. I'm not using Mint either.

Copy link
Contributor

@polvalente polvalente left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verbs should be changed and tests need to be added

@@ -71,7 +71,7 @@ defmodule GRPC.RPCError do
%{error | message: error.message || Status.status_message(error.status)}
end

def from_status(401), do: exception(GRPC.Status.unauthorized(), status_message(401))
def from_status(401), do: exception(GRPC.Status.unauthenticated(), status_message(401))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

401 is unauthorized as per HTTP specs

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we should use the same verbs as HTTP if we are to do any kind of translation here

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, shouldn't the mint client also have similar changes?

Copy link
Contributor Author

@v0idpwn v0idpwn May 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, @polvalente. There's only so much we can do without adding new errors to the library. As the GRPC specification states only 16 error codes, what we do is only a best effort. I copied all the matching pairs from the official implementation in Go

Copy link
Contributor Author

@v0idpwn v0idpwn May 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, @polvalente. I managed to write tests, but found that adding the status handling to the mint adapter is quite complex due to current adapter structure. Can't we perhaps open an issue for a mint implementation of this feature in the future? Maybe someone with a better grasp of the mint adapter (or even future me) can take it

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather have them being feature-equivalent as one is meant to be a drop-in replacement of the other.

Can you elaborate on what made it difficult to add this kind of handling?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Essentially, the status is received at ConnectionProcess, which is called to start the request, but the calling process reads the response from the StreamResponseProcess. Meaning I'd need to write some process coordination or rework current coordination logic. Since I don't fully understand the current architecture decisions (yet?), I found this a bit challenging.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

client_adapters = [GRPC.Client.Adapters.Gun, GRPC.Client.Adapters.Mint]

for {http_code, expected_error_code} <- error_table, client_adapter <- client_adapters do
test "#{client_adapter} returns RPC Error when getting HTTP #{http_code}" do
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure where I should put these tests

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems fine

@sleipnir
Copy link
Collaborator

@v0idpwn any progress here?

@v0idpwn
Copy link
Contributor Author

v0idpwn commented Jun 19, 2024

Hi, @sleipnir. I did an attempt at implementing it on the mint adapter, but ended up hitting a wall. I'll give it another stab soonish.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants