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

How to send errors back to the client? #123

Closed
MrMage opened this issue Feb 20, 2018 · 2 comments
Closed

How to send errors back to the client? #123

MrMage opened this issue Feb 20, 2018 · 2 comments

Comments

@MrMage
Copy link
Collaborator

MrMage commented Feb 20, 2018

(I've found #10 and #88 on this, but no further information, and not sure whether these are referring to this.)

Looking at the generated server code (see Plugin/Templates/server.swift) surfaces the following handler code:

  do {
    switch handler.method {
    case "/service/operation":
      try Service_OperationSession(handler:handler, provider:provider).run(queue:queue)
    default:
      // handle unknown requests
      try handler.receiveMessage(initialMetadata:Metadata()) {(requestData) in
        try handler.sendResponse(statusCode:.unimplemented,
                                 statusMessage:"unknown method " + handler.method,
                                 trailingMetadata:Metadata())
      }
    }
  } catch (let error) {
    print("Server error: \(error)")
  }

It appears that errors thrown in try Service_OperationSession(handler:handler, provider:provider).run(queue:queue) simply never return a result whatsoever to the client, instead of returning the appropriate StatusCode. Should this be changed, to at least let the client know that something bad happened instead of just going radio silent? It might also be nice to have the option to e.g. return custom status codes or messages to the client. A simple approach could simply try sending a response with an error status code in the catch block.

@MrMage
Copy link
Collaborator Author

MrMage commented Mar 17, 2018

Errors will be sent back properly once #184 is merged.

@MrMage
Copy link
Collaborator Author

MrMage commented Mar 22, 2018

Done with #184.

@MrMage MrMage closed this as completed Mar 22, 2018
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

No branches or pull requests

1 participant