How to choose HTTP status code for unavailable event - node.js

Description:
The user inquires about the availability of the event on a given day.
Question:
Which response code should I send back if new event can not be created on this day? 404? 400? 422?
My choice:
I chose the "404 Not Found" status code:
{
"statusCode": 404,
"error": "Not Found",
"message": "The event can not be created on the selected date."
}

As a response to a POST request I would use the 422 Unprocessable Entity status code along with a description of why the request could not be processed.
If you only want to test if there is already an event at this day, perform a GET request (for example: /event/2019-06-01) to check if it exists.
If it does not exist yet, respond with a 404 not found.

Your question is entirely opinion based. You should try learning about various status codes and their reasons. In your case, you may find status code 410 useful, but again, this is entirely opinion based.

Related

Dialogflow Webhook call failed. Error: [ResourceName error] Path '' does not match template

I am using Dialogflow ES and once I got the webhook setup, I haven't been having issues. But after a few months, I just started getting a random error. It seems to be inconsistent as in sometimes I get it for a specific web call and other times it works fine. This is from the Raw API response:
"webhookStatus": {
"code": 3,
"message": "Webhook call failed. Error: [ResourceName error] Path '' does not match template 'projects/{project_id=*}/locations/{location_id=*}/agent/environments/{environment_id=*}/users/{user_id=*}/sessions/{session_id=*}/contexts/{context_id=*}'.."
}
The webhook is in GCP Functions in the same project. I have a simple "ping" function in the same agent that calls the webhook. That works properly and pings the function, records some notes in the function log (so I know the function is being called), and returns a response fine, so I know the webhook is connected and working for other intents in the same agent before and after I get the error above.
Other intents in the same agent work (and this one WAS working), but I get this error now. I also tried recreating the intent and I get the same behavior.
The project is linked to a billing account and I have been getting charged for it, so I don't think it is an issue with being on a trial or otherwise. Though the Dialogflow itself is in "trial", but the linked webhook function is billed.
Where can I find what this error means or where to look to resolve it?
After looking at this with fresh eyes, I found out what was happening.
The issue was a mal-formed output context. I was returning the bad output context sometimes (which explained why sometimes it worked and sometimes it didn't). Specifically, I was returning the parameters directly into the output context without the output context 'name' or 'parameters'. Everything looked like it was working and I didn't get any other errors, but apparently, when Dialogflow receives a bad web response, it generates the unhelpful error above.

Express js not returning full error on status code 500 but does with code 200

I have an express js project that has a try catch, when i respond with status code 500 i get no error detail returned.
Below you can see that when i return status code 200 i get a full response with the error and in this case 'Invalid time value'.
But when i change to status code 500 i get hardly any information, how do i send status code 500 but still get full error information?
this output is normal based on Hypertext Transfer Protocol, you can check the details about status codes here.
when status code is 200
The request has succeeded. The information returned with the response
is dependent on the method used in the request, for example:
GET an entity corresponding to the requested resource is sent in
the response;
HEAD the entity-header fields corresponding to the requested
resource are sent in the response without any message-body;
POST an entity describing or containing the result of the action;
TRACE an entity containing the request message as received by the
end server.
when status code is 500
500 Internal Server Error
The server encountered an unexpected condition which prevented it
from fulfilling the request
this outputs is Hypertext Transfer Protocol and its normal

Azure API Manager POST Request/Response Limit 65,535

I have an Application API wrapped in API Manager on Azure cloud service. For whatever reason when I send in a JSON payload of 1000 records or more (which translates to around 200k chars) the request is dropped. No trace, no logging just dropped but if I truncate the payload everything works as expected. If I send the same 1000 record payload into the underlying service (not through API Manager) all works as expected. Is there a request or return size limit when using APIM?
My underlying service was matching inner response codes and applying to overall return code if they were the same. My inner codes were all 404 "item not found". Azure API manager treats a 404 as an error and drops large payloads. This is per their support. On a small return payload it will return a code of 404 and the message but on a large payload it is dropped. Reason I was trying to return 404 is because each record in the return payload contains a status. If the status is mixed return 207 for mixed status but if they are all the same - 200 for found and 404 for not found the overall service was returning the internal status as the overall status. This was bad design. My payload consisted of a search for items that did not exist in the DB and therefore was returning 404 as overall status with messages for each record indicating "Not found". APIM was dropping the return response in favor of a generic 404 url not found response. Switched the internal service to return only 200 or 207 depending on outcome and all is right.
{
"ProcessId": "2",
"Code": 404,
"Message": "Could not resolve token.",
"Token": "#!!!#xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
},
{
"ProcessId": "2",
"Code": 404,
"Message": "Could not resolve token.",
"Token": "#!!!#xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
},
Overall return code was set to 404 and APIM dropped the response. I fixed this by setting overall return code to 200 in this case.

"500 Backend Error" using Gmail API - safe to retry?

I'm sending messages via the Gmail API. In particular, I am trying to send 5-7 emails from the same account to different users (1 each) within about 2 seconds.
About 8% of those emails are failing with this error:
&googleapi.Error{
Code:500,
Message:"Backend Error", Body:`{
"error": {
"errors": [
{
"domain": "global",
"reason": "backendError",
"message": "Backend Error"
}
],
"code": 500,
"message": "Backend Error"
}
}`,
Header:http.Header(nil),
Errors:[]googleapi.ErrorItem{
googleapi.ErrorItem{Reason:"backendError", Message:"Backend Error"}
}
}
It doesn't seem like it's specific to a particular account, as 6/7 emails may succeed.
I'm hesitant to retry this for fear of sending 2 emails to the same person.
Is there any way to tell whether this message is safe to retry?
"code": 500, "message": "Backend Error"
Is basically an issue with Google server. Either the request you are making took to long or the server preforming the request is busy and the request again took to long. It doesn't sound like what you are doing should be causing the problem.
Tips when not to run: Don't run on the hour you will be completing with everyone who has cron jobs set up also don't run at midnight (PDT) as this is when quotas reset and again you will be completing with everyone who blew out yesterdays quota.
Solution:
The normal solution is to wait a few seconds then send the same request again. (Implementing Exponential Backoff)
The flow for implementing simple exponential backoff is as follows.
Make a request to the API
Receive an error response that has a retry-able error code
Wait 1s + random_number_milliseconds seconds
Retry request
Receive an error response that has a retry-able error code
Wait 2s + random_number_milliseconds seconds
Retry request
Receive an error response that has a retry-able error code
Wait 4s + random_number_milliseconds seconds
Retry request
Receive an error response that has a retry-able error code
Wait 8s + random_number_milliseconds seconds
Retry request
Receive an error response that has a retry-able error code
Wait 16s + random_number_milliseconds seconds
Retry request
If you still get an error, stop and log the error.
Sometimes it can happen before send and sometimes after send.
I logged the "To" and "From" from five different email attempts that all received a 500 Backend Error. None of these attempts made it to the "Sent" folder of my inbox. I conclude that they were never sent, and it's safe to retry these messages. However, other people in the comments (see below) indicated that the messages actually made it to the remote mailbox, and it's not safe to retry.

Sharepoint 2013: unexpected response from server. The status code of response is ‘500’

I have term driven navigation when I try to add new term in "term store management", on the TERM-Driven-page link I am getting below mentioned error.
Unexpected response from server. The status code of response is 500.
The status text of response is
system.servicemodel.serviceactivationexception

Resources