RPC JSONP error object conventions - object

Im building a php json(p) rpc server and currently i am stuck with not finding sufficient information on how to handle/respond if a jsonp call throws an error inside the called function/method. With json rpc 2.0 its well documented - with jsonp its not. how to return errors from the application level of the service called?
Suppose a call like /service.php?var=test&callback=jsonpCallback is requested. in a positive case the result would be something like jsonpCallback({"result": "test"}). Suppose on the application level an exception is thrown? what do i return and how?
Do i return an error object inside the callback? or just a json (custom) error object as string? If there is something like an jsonp error object convention where to find it?
Does make sense to allow for a custom error callback in the GET request which can be called like: /service.php?var=test&callback=jsonpCallback&errorCallback=jsonpErrorCallback
Any advice highly appreciated.

Related

How the Get action method is getting called in Docusign API example

This is a newbie question about the DocuSign API. I just downloaded the C# example. Excellent flow, which demonstrates the API capabilities. But I do not understand how the Get() action method is getting called in eSignature\Controllers\EgControllers. I do not see any route to the Get() action method and the default routes defined in Startup.cs point to an Index action method, not Get. Shouldn't the Get() action method be named Index()?
I assume you downloaded a C# Quickstart that include a lot of calls built using the C# SDKs.
The C# eSignature SDK is making all calls for you, including the GETs.
When you use an SDK, it's a wrapper that handles the calls for you, so you don't have to worry about GET or POST or JSON.
For example, this line in the C# code you have (eSignature/Examples/GetEnvelopeInformations) is making a GET call inside the SDK:
return envelopesApi.GetEnvelope(accountId, envelopeId);

Spring Integration Java DSL InBound and Outbound Error Handling

I am trying to build an integration solution where
IntegrationFlows
.from(inBoundGateway)
.enrichHeaders(enrichHeaders())
.transform(dto to externaldto)
.handle(outBoundGateway, advice -> advice.advice(retryAdvice()))
.transform(exetrnaldto to dto)
.get()
#Bean
RequestHandlerRetryAdvice rhra
rhra.setRecoveryCalBack(errorMessgaeRecoverer());
#Bean
ErrorMessageSendingRecoverer errorMessgaeRecoverer
and my outboundgateway is defined as
Http.outboundGateway(uri, resttemplate)
...
.get()
new RestTemplate(requestFactory)
where requestFactory is
TrustStratgey ts = new TrustStratgey(){
public boolean isTrusted(...){
return true;
}
}
SSLContext context = SSLContexts,custom().loaddTrustMaterials(null, ts);
SSLContextFactory cf = new SSLContextFactory(context, new NoopHostnameVerifier());
HttpClientBuilder clientBuilder ..
clientBuilder.setSSLSocketFactory()
Happy path works fine, the problem i am facing is with not so happy path.
When Api call returns Error response .transform(exetrnaldto to dto) fails and client get 500
I want to translate error resposne json as well to my json
How do i handle error situations.
My questions are;
How to handle errors.
In error conditions how to stop flow not to transform
How to send status code in response from outbound to client (this is important)
How to handle error like typical #Controller Advice #ErrorHandler mechanism or similar.
Hope Garry get to see this post, couldnt find any answers, i looked through many books and forums, feels like Java DSL is not widely used or commented yet.
There is nothing Spring Integration Java DSL specific in your question.
It is really more about how to handle HTTP error on the server side (MVC - HttpInboundGateway) and on the client side - RestTemplate and HttpOutboundGateway.
The Java DSL is just a syntax sugar over existing technologies and solutions.
So, the #Controller Advice #ErrorHandler is an MVC, server side. You definitely can make it working with the HttpInboundGateway, but it is indeed wrong direction for the client side REST calls.
It looks like you would like to catch a REST error call for that your .handle(outBoundGateway). Consider to use an ExpressionEvaluatingRequestHandlerAdvice along side with that retryAdvice. So, you will be able with its failureChannel to handle an exception and transform it into a desired JSON respectively.
See more in docs: https://docs.spring.io/spring-integration/docs/current/reference/html/messaging-endpoints.html#expression-advice

DDD / CQRS - Does a request handler (or controller) can throw exceptions defined at the domain level?

Good morning,
Let's say, we've a domain defining an exception such as ObjectNotFoundException which expect an identifier (VO), defined at the domain model.
Question
Can we throw domain exceptions from the request handlers directly, for instance:
class ObjectRequestHandler implements RequestHandler
{
...
public function __invoke(Request $request, Response $response)
{
// Will self-validate and throw an exception if not a valid UUID
$objectId = ObjectId::fromString(strval($request->param('object_id'])));
$object = $this->repository->find((string)$objectId);
if (NULL === $object) {
// Exception defined at the domain level...
throw new ObjectNotFoundException($objectId);
}
...
}
}
Doing this also lead to usage of the identifier VO in the request handler... It MUST be also noted that the throwed exception will be catched by the default exception handler which in turn, will prepare and send a JSON response.
Finally, note that the request handler here, is an implementation detail, not part of the question. Please don't comment about it.
Thank you.
Your example shows the correct usage of the repository to fetch an object from the data store based on an identifier.
Let's unpack and expand the workflow a little more to fit the paradigms of DDD, to help answer the question:
API Controller (or Request Handler) would invoke an Application Service with request params sent by the callee.
Request params forwarded to the Application Service can be simple data (like JSON) or can be objects (like DTOs)
Application Service has access to the correct repository associated with the object.
Repositories are outside the domain layer
Application Service would load the objects into memory using these repositories before handing over the control to (or invoking a method in) the domain layer.
The ObjectNotFound error is thrown typically from the repository if no object is found for the given identifier
The domain layer typically receives all objects it needs to work on from the Application Service or builds objects using factory methods.
The actual process is all about assigning or transforming attribute values according to business rules while ensuring invariant rules are satisfied. So the kind of errors that Domain Layer throws is Business Rule Errors (or Validation Errors).
So,
ObjectNotFoundException is not a Domain Exception
You are not at the domain level yet, so calling the identifier as a ValueObject is incorrect
Ignoring Application Services for a moment, you are spot on in your usage of the concept. The code example is correct in structure. It's just the terms that need to be clarified.

Default error handler for node express

I've read the error handling guidance given for the express module, but would like to dig a little deeper and see exactly what the default error handler in express actually does (and hence what my custom error handler should and shouldn't do, if it can pass on some of the basic error handling procedure on to the default handler). It may just be showing my ignorance, but I can't for the life of me find where the default error handler is actually defined in the express source code. Please can someone help me out here.
Pretty sure the default handler just logs to stderr. Look at the logerror function and how it's used in the "finalhandler".
https://github.com/expressjs/express/blob/master/lib/application.js

Globle error filter in node js

I am working on node from last 2-3 months on a project. Now I want to handle errors from a single point in node. For example : I have several api functions in my project. Many of them are taking _id as an api input. I need to parse this id using mongoose objectid before using in query. Now if the format of _id is not valid, it will throw the casting error. It could be handled by mongoose object isvalid property. But my purpose is that, at any place if it is not handled in code I want to catch the error and log it to my log file and send a common message like 'error occurs' to the UI. I want to add a common error handler for all the api that do the logging and error handling for my api, like we use .net MVC - error handler filer through the application.
I have tried using domain. But in domain.on('error',func(err){}); it is not working. I put my api functions call in domain.run();
If any body have any suggestion for me, please let me know.
Take a look at the domain module, if your app powered by express you can use the package - express-domain-middleware

Resources