Fsockopen error handling, at the moment I get warnings and page stops further content from loading - error-handling

I have the following code:
$open_socket = fsockopen($host,$port,$errno,$errstr,30);
if(!$open_socket){
echo "$errstr ($errno)<br />".$nl;
}else{
fputs($open_socket,$xml);
while(!feof($open_socket)){
$line = fgets($open_socket,128);
$return_xml.= $line;
}
fclose($open_socket);
}
but if there is not connection I get the following message:
Warning: fsocket ......
the rest of the page is blank, basically how can I handle this where my page will continue and things will be displayed and just the error message is displayed and not the warning.
Thanks

You can supress warnings calling fsockopen
$open_socket = #fsockopen($host,$port,$errno,$errstr,30);

Related

Error.cshtml in a modal pop up in ASP.NET CORE 2.1 (using exception handling middleware)

I am using asp.net core exception handling middleware (app.UseExceptionHandler). I have written a code to display user friendly errors in Home Controller in Error action method. I have also written a code in Error.cshtml view to display the content in a modal pop up.
Everything is working as expected. Error.cshtml is loading in a modal pop up. The challenge over here i am facing is that the Error.chtml is redirecting first and then loading a modal pop up.
I am looking for a solution where i can load Error.cshtml in a modal pop up without having it redirected. i.e. on the same page where error is occuring (example: Edit).
If anyone has a suggestion on how to achieve this, that would be great.
For reference, I am doing what Edward has proposed in this thread: https://forums.asp.net/t/2130016.aspx
Thanks
I found
var exceptionFeature = HttpContext.Features.Get<IExceptionHandlerPathFeature>();
if (exceptionFeature != null)
{
ViewBag.ErrorMessage = exceptionFeature.Error.Message;
ViewBag.RouteOfException = exceptionFeature.Path;
ViewBag.Stacktrace = exceptionFeature.Error.StackTrace;
ViewBag.ViewName = "_ErrorView";
ViewBag.Header = "Error";
}
add this in the ErrorController. Add the error message to the TempData
TempData["ErrorMessage"] = ViewBag.ErrorMessage
then redirect to the view from where the exception was thrown which will be in
ViewBag.RouteOfException
then in the originating view:
ViewBag.ErrorMessage=TempData["ErrorMessage"]
#if (ViewBag.ErrorMessage != null)
{
<partial name="_ModalPopUp" />
}

Unable to get the alert text using selenium webdriver

I have the below code to verify the alert text and then dismiss. Verifying the alert text is failing.
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.alertIsPresent());
Alert alert = driver.switchTo().alert();
alertText = alert.getText();
alertText is returned as null. So the next step to assert the text is failing.
Next step:
driver.switchTo().alert().accept();
Accepts the alert without any issue.
Another weird scenario is when I debug in eclipse its working fine. But when I am running assertion throws error.
Another differecnce I found while running and debugging.
During running the alert come with this message don't let this page create more messages
Looks very weird.
Showing message as "don't let this page create more messages" is browser feature there to prevent sites from showing hundreds of alerts.
As while debugging your code it is working, it should work even while running too. If not working, definitely its sync issue. I hope adding some hardwait definitely help.
Other approach to get alert text from alert popup:
public String getJsAlertText()
{
Object txt = ((JavascriptExecutor)driver).executeScript("return
window.alert.myAlertText;");
return (String)txt;
}

Set message inside the add dialog in jqgrid if error occurs

I am returning the following from my action (asp mvc) if error occurs upon adding the record to jqgrid
return new HttpStatusCodeResult(400, "item not found");
It's all great but the message displayed inside the add dialog is
"error Status: 'Workorder not found'. Error code: 400"
Is there any way to just show the "Item not found" message only?
It looks like the js never goes to afterSubmit routine in add options. Any way to gain the control and make sure that only the actual error message shows? Something like onError option would be great!
You can use errorTextFormat callback of form editing or jqGridAddEditErrorTextFormat event of jqGrid to control the format of the text from the error message. The first parameter of errorTextFormat callback (or the second parameter of jqGridAddEditErrorTextFormat) is jqXHR Object which is superset of XMLHttpRequest. The responseText property of the parameter is the text of the response body.
Moreover you should not use HttpStatusCodeResult for error description. Instead of that you should place the error description in the body of HTTP response. You can use WebFaultException for example to do this:
return throw new WebFaultException<string> (
"item not found",
HttpStatusCode.BadRequest); // 400
By the way the HTTP status code 404 (HttpStatusCode.NotFound) seems me more corresponds to the error "item not found".

selenium : how to handle error messages that get displayed when we dont give credentails

I am new to selenium, and when testing a web application I want to check when credentials are wrong the message in alert which gets displayed and the error message that is displayed on the page after accepting the alert are same or not please can anybody help me how can I do this
I have handled alert using
web.swichto.alert().accept
but I want to compare the message that alert displays and the error message that is displayed in that page like
Error: Invalid User ID/Password Or Network Is Down!
and message in alert box like
Invalid username/password
thanks in advance
you can store text present in the alert into a variable as follows,
String msg_in_alert=driver.switchTo().alert().getText();
then you can use assert to compare,
Assert.assertEquals(driver.findElement(By.cssSelector("selector_of_error_element")).getText().compareTo(msg_in_alert), true);
"true" specifies that the text should match..
If text does not match,it will result in step failure...
WebElement element = _driver.findElement(By.xpath("//span[#class='ng-binding error-class ng-hide']"));
element.getText();
if(element.equals("Recall and Volume data does not exist for calculation. Please upload the data.")){
System.out.println("true");
}else{
System.out.println("false");
}
WebElement mandmessActionName = driver.findElement(By.xpath("//*[#id='container']/div/form/div[1]/div/fieldset/div[1]/div/span[1]"));
String mandmessActionName1 = mandmessActionName.getText();
if (mandmessActionName1.equals("Action Name is required."))
{
System.out.println("true");
}
else
{
System.out.println("false");
}

Apache wicket validation

I have custom validation added to my page, and this validation is called from business logic layer, after I click "Save" button on UI, which is AjaxSubmitLink.
On my page I have apache wicket DateTimeField, but it's validation doesn't work correctly: error message doesn't appear in FeedbackPanel, which is added on page and my custom validation is shown there correctly.
So for example I fill hours field with "321" and I will have error in console:
WARN org.apache.wicket.protocol.http.WebSession -
Component-targetted feedback message was left unrendered. This could
be because you are missing a FeedbackPanel on the page. Message:
[FeedbackMessage message = "Translation for key [hours.RangeValidator]
is not found for language [en]!", reporter = hours, level = ERROR]
Maybe someone had similar problems and have solution for this?
Thanks!
Because you do an Ajax-Request you have to add the feedback-panel to your AjaxRequestTarget (so it will update itself on every request).
You have to override the onError method though:
add(new AjaxSubmitLink() {
#Override
protected void onError(final AjaxRequestTarget target, final Form form) {
target.addComponent(yourFeedbackPanel);
}
}