When I Uncomment this line for api documentation
//// Uncomment the following to use the documentation from XML documentation file.
config.SetDocumentationProvider(new XmlDocumentationProvider(HttpContext.Current.Server.MapPath("~/App_Data/BitCoinWrapperAPI.xml")));
I received an error :
An exception of type 'Microsoft.Practices.ServiceLocation.ActivationException' occurred in Microsoft.Practices.ServiceLocation.dll but was not handled in user code
Additional information: Activation error occured while trying to get instance of type HelpController, key ""
When I call the Index page in the HelpController of the API, anybody knows why?
Well I added this line and it works without exception
ObjectFactory.Configure(x => x.SelectConstructor(() => new HelpController()));
Related
I'm using the NestJS #FilesInterceptor to parse an array of files in a multipart request, here's how I use it:
#FilesInterceptor('files', 3, { some other options })
I need a specific error to be thrown if more than 3 files are sent, but what I get is a socket hangup client-side
Error: socket hang up
and this is the error logged in the console of the server:
Error: Unexpected end of multipart data
In the end: server crashed :(
So, how can I catch this error to handle it and prevent crashing?
It doesn't seem to be an instance of HttpException so the exception filter is not useful.
I could have done the length check in the controller, but I need { some other options }, so I must set a value for the maxCount
I found out the problem: the server has a global interceptor that implements a timeout for incoming requests. If I remove it, then the error is parsed correctly to an HttpException the client gets a BadRequest as expected
I'm still confused about why this doesn't work when I put it all together...
From the Apigility documentation (Error Reporting):
The API Problem specification allows you to compose any other additional fields that you feel would help further clarify the problem and why it occurred. Apigility uses this fact to provide more information in several ways:
Validation error messages are reported via a validation_messages key.
When the display_exceptions view configuration setting is enabled, stack traces are included via trace and exception_stack properties.
I don't understand this part of the docu. What is the purpose and how to use the settings validation_messages and display_exceptions?
The display_exceptions setting is from ZF2's view manager (see docs here). Turning this on will cause Apigiltiy to include a stack trace with any error response.
In Apigility itself the validation_messages key population is handled automatically. You configure an input filter which validates the incoming data payload and if the input filter fails the error messages it returns are automatically injected into the API response under the validation_messages key. This functionality is provided by the module zf-content-validation. You can "do it yourself" by returning an ApiProblemResponse from your resource like so:
return new ApiProblemResponse(
new ApiProblem(422, 'Failed Validation', null, null, array(
'validation_messages' => [ /* array of messages */ ]
))
);
I have a question regarding to Nest1.0pr and the connection error handling. In the previous versions of Nest I was using IResponse.ConnectionStatus.Error. It seems to me that the property Error does not exist in the new version anymore. However in the documentation I found the following:
ConnectionStatus is the response as it was returned by
Elasticsearch.net. It's section on handling responses applies here as
well.
And in the very section the property Error is mentioned.
Error When a call succeeds but does not return a http status code of
200 this property will have details on the error. Read more about
error handling here
So is the recommended way to check whether the property Success is false?
TIA
This changed when NEST was refactored to use Elasticsearch.Net. Now when a request fails, you can try checking the IResponse.ConnectionStatus.OriginalException property, which will contain the actual Elasticsearch error.
I'm trying to get SimplePie to fail gracefully if one of the feeds I hand it turns out to be unavailable or invalid (due to server issues on the feed provider's end)
The code I've got is this:
$this->feed= new SimplePie();
// Set which feed to process.
$this->feed->set_feed_url('http://my_feed_goes_here'); // Bogus
$this->feed->handle_content_type();
// Run SimplePie.
$this->feed->init();
The problem is, if the feed_url turns out to be invalid, I get the following error as soon as it hits $this->feed->init();
Fatal error: Call to undefined method DOMElement::getLineNo()
I've looked through the documentation, and I can't see anything about validating. I did see this page about error checking (http://simplepie.org/wiki/reference/simplepie/error) but that only really works if the URL is completely invalid and fails to load. In a case where the URL comes back with a 404, or something else that is not a valid feed, $feed->error is blank.
Isn't there some mechanism built into SimplePie to allow me to see whether I got a valid feed back, so I can fail gracefully if I didn't?
In SimplePie 1.3.1, ->init() will return false if it can't read or parse the URL, so you might do this:
if (! $feed->init()) {
// log your error, "return false" or handle the failure some other way
}
Based on my reading of simplepie\library\SimplePie.php, it doesn't generate any exceptions and that's why Try/Catch won't work.
This may not be built into SimplePie, but in your calling PHP you could use a try/catch block:
try {
$this->feed->init();
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
Although depending on the error, this might not work either.
I am using the following code to send Error message.
This is my own error code and custom message. I am sending the message in response.
throw new WebApplicationException(
Response.status(1002)
.header(ae.getMessage(), ae)
.type(MediaType.TEXT_PLAIN)
.build());
The problem is, the front end guys are able to see the status code but not the message. Is there any other way to solve this issue?
You should use entity method to set message:
Response.status(1002)
.entity(ae.getMessage())
.type(MediaType.TEXT_PLAIN)
.build());