Display custom error message in ajax over HTTP/2 - ajax

In my MVC application, I have used Ajax's Response.StatusText to display custom error messages to user whenever there is some error.It works fine but when I deploy my application on AWS, the StatusText gets removed and only the code is displayed. Got to know that because of using HTTP/2, the statusText gets removed.
Is there a way to show custom error message in Ajax error over HTTP/2 ?
Thanks in advance.

I don't think the HTTP Status is the best place to put these. You should either put this status in the body, or possibly in a custom HTTP header.

Related

AWS API gateway really works well but I can't run this on javascript AJAX

I made python function using AWS lambda and connected lambda with API Gateway
After then, I tested API. It worked well.
Testing in API Gateway was Successful
Now I tried to using this API with AJAX.
Javascript AJAX Code was like this
How ever result was
"jquery-3.4.1.js:9837 GET https://9i1jhuewmj.execute-api.ap-northeast-2.amazonaws.com/test/transaction?jpgname=image.jpg net::ERR_FAILED"
How can i solve this problem??
Hope for your wisdom!
Thank you
I think there are a few things. The content-type header being returned is application/json but the response is not JSON.
But I think the main problem is that the HTTP status being returned is 301. This tells the browser that this resource has been moved and the browser typically expects the response to contain information on where things are moved to so it can redirect.
I suspect if you change your configuration so that a more normal response code (i.e. 200) is returned, this will work better.

JMeter & Salesforce : Facing an error as 'Error occurred while loading a Visualforce page. Attempt to de-reference a null object'

I am creating script in JMeter for a Salesforce application but I am Facing an error as
Error occurred while loading a Visualforce page. Attempt to de-reference a null object' for one of my POST request.
Response code received is 500 with message 'Server Error'
HTTP Status 500 stands for Internal Server Error, you should look into your server logs in order to get to the bottom of the issue.
If you don't have access to your application logs - you can perform some client-side troubleshooting, the common way is to capture the request which is being sent by JMeter and the real browser using a sniffer tool like Wireshark or Fiddler and compare them. The requests should look exactly the same (apart from dynamic values which need to be correlated)
You should pay attention not only to the request body, but also HTTP Headers (including Cookies) as everything matters.
You might also want to check out JMeter – Logging Into Salesforce for Automated Testing article

django-rest-framework: how to allow http PUT to succeed

I have a startup django-rest-framework app, which I'm using to serve data to another Django app
I have no issues with GET, POST, and DELETE, but when I issue a PUT - I get 405
What can I do to fix that?
if I'm remembering well, I has the same issue. Following the tutorial of django-rest-framework I noticed that pressing PUT botton request and monitoring network tab of chrome developer tools it did a POST request instead of PUT request.
Maybe '405 METHOD NOT ALLOWED' error message caused by request without '/' at the end of the url.
Not working 127.0.0.1:8000/article/9
Working 127.0.0.1:8000/article/9/
If not, check how you request it. It's similar to request DELETE method.
This is an example I've just testing using PAW http client application
PUT Method request screenshot
PUT Method request result screenshot

How to add the unhandled exceptions accross the applications in response body in WEB API

How to add the unhandled exceptions accross the applications in response body in WEB API. If there is no exceptions a success message needs to be sent to the response body for all the responses....Need help on achieving this.
You need two things. For handling the exceptions, you need to set the IncludeDetailErrorPolicy in the HttpConfiguration object,
You can configure the error policy preferences as part of the configuration object (HttpConfiguration) in the IncludeErrorDetailPolicy property. This is just an enum that instructs Web API about how to deal with exceptions.
The possible values for this enum are,
Default: It’s uses the customErrors configuration settings if you are using ASP.NET as host or LocalOnly for self-host.
LocalOnly: Only includes error details for local requests
Always: Always includes error details
Never: Never includes error details
When an exception happens, Web API will check the value on this setting for including details about the exception in the response message or not. For example, if Always is enabled, Web API will serialize the exception details as part of the message that you get as response.
The success message does not make much sense as you already have the response status code. A status code equals to OK means that everything went ok. If you still want to add an additional message, use a HttpMessageHandler that checks for the response status code. If the status code is OK, add the message. However, the response body has been set already at that point so you will not able to modify it. You might able to add a message as a header.

How to get custom module configuration gui to send info to another web server?

Firstly, I have to admit I am new to Magento and PHP. I am writing the configuration for my custom module. I would like to allow entry of some information, then send that information to a servlet on my web server where it is processed and a response returned and displayed in the configuration gui in a read-only field.
I am getting my guidance from various web articles and by looking at other modules' code. A module that does something similar is the PayPal module. However, it brings up a new browser window where the user logs in and enters their details. I just want to send the data gathered and wait for the response.
In my system.xml file I specify a frontend_model. In that frontend_model, the _prepareLayout method sets the template to my template, and in that template I have an HTML button. I added an onClick event handler to that button which makes an AJAX call to my web site. Unsurprisingly (because of the same origin policy I assume) the AJAX call fails with a code of 0.
I guess what I should be doing is when the user clicks the button, the request including the data they have entered in the other fields, is sent to the Magento server, and the AJAX call to my web site is made from there? Or perhaps my approach is completely wrong and there is a more appropriate way to achieve this?
Thank you.
You're right about the same origin policy. The best approach here would be to have the button trigger an ajax call to a local magento based controller, which itself uses curl or some other http request library to forward on a request to your remote servlet and process the feedback.
Try searching here "JSONP" or google the same thing. Dependent of javascript library you are using there are pre-made components/plugins to achieve what you are after.

Resources