question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

GlobalErrorHandler breaks precessing response and not executing response-middlewares

See original GitHub issue

I need to transform error response by middlewares, such as normat responses.

GlobalErrorHandler breaks precessing response and not executing ResponseExtractMiddleware, EncodeJsonMiddleware.

middlewares: [
    GlobalErrorHandler,
    ResponseExtractMiddleware,
    EncodeJsonMiddleware,
  ],
const ResponseExtractMiddleware = () => ({
  response(next) {
    return next().then((response) => {
      console.log('ResponseExtractMiddleware->response:63', response);

      return {
        status: response.status(),
        data: response.data().data,
        headers: response.headers(),
      };
    })
  },
});
const CONTENT_TYPE_JSON = 'application/json;charset=utf-8';
const EncodeJsonMiddleware = () => ({
  request(request) {
    try {
      if (request.body()) {
        const content = JSON.stringify(request.body());
        return request.enhance({
          headers: {'Content-Type': CONTENT_TYPE_JSON},
          body: content,
        });
      }
    }
    catch (e) {
      return request;
    }
  }
});

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
tulioscommented, Mar 14, 2017

Thanks for reporting, I’ll improve the docs based on this ticket. Thanks again!

0reactions
ar2rcommented, Mar 14, 2017

It`s correct example. return in catch will convert exception to good responce.

const ResponseExtractMiddleware = () => ({
  response(next) {
    return next()
      .then((response)=>{return response;})
      .catch((response)=> {throw response;})
  }
})
Read more comments on GitHub >

github_iconTop Results From Across the Web

Mule 4 error handling deep dive - MuleSoft Blog
The answer is: utilize the On Error Continue scope in your global error handler. Payload is successfully set to “Success – Started Flow”;...
Read more >
Mule 4 Error Handling Tutorial | On Error Propagate - YouTube
How to use Global Error Handler in Mule 4. * How to use Catch Scope in Mule 4. * How to transform Error...
Read more >
The mappersmith from tulios - GithubHelp
GlobalErrorHandler breaks precessing response and not executing response-middlewares. I need to transform error response by middlewares, such as normat ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found