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

Custom error message in error response #977

Open
AdiSegev opened this issue Feb 6, 2020 · 8 comments
Open

Custom error message in error response #977

AdiSegev opened this issue Feb 6, 2020 · 8 comments

Comments

@AdiSegev
Copy link

AdiSegev commented Feb 6, 2020

Hi,

I've start using your library and it's very easy to use one.
I wanted to add handshake reject mechanism, so I've looked at your ServerRejectHandshakeExample.
There I can see the way I can reject the request.
But I've noticed that the message I write in the InvalidDataException constructor is not visible to the client.
When I've looked on your source code it I saw you're ignoring it while you're passing only status code of 404/500 to generateHttpResponseDueToError I'd suggest you to either let the developers a way to override generateHttpResponseDueToError method, or change it to something like this:

  private ByteBuffer generateHttpResponseDueToError(Exception exception) {
        String errorCodeDescription = "UnExpectedException";
        String errorDescriptionTitle;

        if (exception.getMessage() != null) {
            errorCodeDescription = exception.getMessage();
        }
        
        if (exception instanceof InvalidDataException) {
            errorDescriptionTitle = "404 "+errorCodeDescription;
        } else {
            errorDescriptionTitle = "500 "+errorCodeDescription;
        }
        return ByteBuffer.wrap(Charsetfunctions.asciiBytes("HTTP/1.1 " + errorDescriptionTitle + "\r\nContent-Type: text/html\nISR Java-WebSocket\r\nContent-Length: " + (48 + errorCodeDescription.length()) + "\r\n\r\n<html><head></head><body><h1>" + errorCodeDescription + "</h1></body></html>"));
    }
@marci4
Copy link
Collaborator

marci4 commented Feb 6, 2020

Hey,

could you please describe your use case?

Thx a lot.
Best regards,
Marcel

@AdiSegev
Copy link
Author

AdiSegev commented Feb 6, 2020 via email

@marci4
Copy link
Collaborator

marci4 commented Feb 6, 2020

To be honest, I would only say that this is a debugging feature, but not required for normal use.
Am I wrong?

@AdiSegev
Copy link
Author

AdiSegev commented Feb 7, 2020 via email

@marci4
Copy link
Collaborator

marci4 commented Feb 7, 2020

Would it not be better to use the normal http status codes for this?

Best regards,
Marcel

@AdiSegev
Copy link
Author

AdiSegev commented Feb 7, 2020 via email

@jmluy
Copy link

jmluy commented Sep 20, 2022

A possible use case is for authorization, when a server expects a different code like 401.

@gvtelio
Copy link

gvtelio commented Sep 26, 2022

Yes, possible use case is 401. Even if you try to send 401, the library just always sends 404.

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

No branches or pull requests

4 participants