How to send the status of WebSocket request in ActionCable - ruby-on-rails

Is there any way to send a status of request to client in ActionCable Channels?
For example, if sent data is invalid (or some unknown exception were raised) I want to error text in response message, otherwise send 'status: ok'. What I have on client side now is subscriber's perform method which returns true in almost any circumstances as we can see from source code (github):
send: (data) ->
if #isOpen()
#webSocket.send(JSON.stringify(data))
true
else
false
In websocket-rails gem there were methods for this: trigger_failure and trigger_success.

Related

Why is my Twilio status callback never called again even with a retry policy set to all?

I'm working with Twilio to send SMS messages and I'm trying to configure it so that it would retry the status callback request if the endpoint returns an error (500):
require 'twilio-ruby'
#client = Twilio::REST::Client.new(account_sid, auth_token)
message = #client.messages.create(
from: '+...',
body: 'Test message',
to: '+...
status_callback: 'https://public-url/ack#rc=2&ct=1000&rp=all'
)
The endpoint I exposed always returns a 500 error, and I'm expecting Twilio to retry the endpoint 2 times. But this doesn't happen, it is never retrying the request.
Connection overrides are supposed to work with the message resource: https://www.twilio.com/docs/usage/webhooks/webhooks-connection-overrides
Why would this not work? Am I missing something or is this just a bug?
Try adding, &sni=y. I know with Ngrok, I need to do this, to see the retries.
Connection Overrides

Microsoft Graph WebHook: Subscription validationtoken blank?

I'm trying to setup a MS Graph webhook subscription for messages, but it appears that Graph is sending a blank validationToken. I'm connecting to https://graph.microsoft.com/beta/subscriptions
My API endpoint works in Postman and successfully returns a plaintext response with only the validationtoken, but when I call MS Graph, I get the following error "Subscription validation request failed. Response must exactly match validationToken query parameter". I've also tried both validationtoken and validationToken as the parameter to look for.
Full error message
"{\r\n \"error\": {\r\n \"code\": \"InvalidRequest\",\r\n \"message\": \"Subscription validation request failed. Response must exactly match validationToken query parameter.\",\r\n \"innerError\": {\r\n \"request-id\": \"f1546835-606d-4bd8-ab3c-dfb2c75285aa\",\r\n \"date\": \"2018-08-10T03:45:56\"\r\n }\r\n }\r\n}"
To create a subscription you need to expose a notification URL with https (You can look at Graph documentation at https://developer.microsoft.com/en-us/graph/docs/concepts/webhooks).
When you send your create subscription request, the first post message your notification URL will receive is a message with a validation token. You have to send this validation token back. Now you should receive notifications on your specified notification URL. Looking at this failure, it looks like the notification URL is not sending the validation token back.
The response should not vary between Postman and MSGraph. If you are still seeing issues, please share your notification url and we will try to get a repro.

Swagger UI showing response body {} and status 0

I am using swagger to create API docs.
My issue is that once we send a call to the API, the browser sends an OPTIONS call and it returns "OK"; after that the browser sends the actual call of API and then I am not receiving the expected output.
Instead of it, it's showing no-content in response and 0 as the response code.
Please can any one help.

firefox addon-sdk : handle http request timeout

I'm building a firefox add-on using the add-on sdk. I need to make a http request to a certain page and I want to handle the connection timeout but couldn't find anything in the api: https://addons.mozilla.org/en-US/developers/docs/sdk/latest/modules/sdk/request.html
What I'm actually looking is a callback in case the client couldn't connect to the server.
Is there a way to achieve this?
The SDK request will always call onComplete, when the request is considered done for the network. This means that onComplete is called in any case, disregarding if the request returned an error or a success.
In order to detect which error you've got, you need to check the Response object's (the object passed to the onComplete function) property "status" (response.status). It holds the status code for the request. To look up status codes, consider the list on the mozilla developer network. If the response status is 0, the request has failed completely and the user is probably offline, or the target couldn't be reached.
A timeout would either be a status code 504 or 0. The implementation would be similar to this:
var Request = require("sdk/request");
Request({
url: "http://foo.bar/request.target",
onComplete: function(response) {
if(response.status==0||response.status==504) {
// do connection timeout handling
}
// probably check for other status codes
else {
// assume the request went well
}
}
}).get();
I personally use a validation function on the request object, which returns me a number which depends whether I've got a correct response, an error from the web server or a connection issue (4xx and 0 status codes).

Actionmailer SMTP Server Response

When sending mail through actionmailer, the actionmailer gets a response from the SMTP server, when its ok, or when its wrong. Is there a way to retrieve this response after sending a mail?
Also when no errors are thrown by the SMTP server?
Our qmail mail server throws a handler id which we want to use for tracing e-mails.
As an example, the server response is this :
250 ok 1308235825 qp 17832
Set return_response: true in the smtp settings and call message.deliver! instead of deliver. This returns the SMTP server response, a Net::SMTP::Response, which contains the server response you're looking for.
If you need a log of all responses from the connection with the server, not just the final result, you'll need to dig into Net::SMTP.
Looking at the the source you can define an observer:
in base.rb
# Register an Observer which will be notified when mail is delivered.
# Either a class or a string can be passed in as the Observer. If a string is passed in
# it will be <tt>constantize</tt>d.
def register_observer(observer)
delivery_observer = (observer.is_a?(String) ? observer.constantize : observer)
Mail.register_observer(delivery_observer)
end
So you could use some code like this in an initialization file:
class MailObserver
def self.delivered_email(message)
logger_info "Sent Message: #{message}"
end
end
ActionMailer::Base.register_observer(MailObserver)
That will log sent mail and you can see if you can get the headers or response from the sent mail object.

Resources