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.

Default and customizable error messages

See original GitHub issue

Hello, I’d like to be able to have a default notifications in case of service errors while being able to override it if I want to notify the user with custom messages.

As a starting point I’ve overridden the errorInterceptor in my configure stage of the app:

App.config ['RestangularProvider', (RestangularProvider) ->
  RestangularProvider.setErrorInterceptor (response, promise) ->
    toastr.error 'There has been an error contacting the server, please try again'
]

This way on every error toastr shows the default notification. Now, since I want to be able to override the message or do custom actions, I’ve tried to use the promise trying to get it returned valued using promise.reject() so in my controllers I could:

UserService.get('me').then (user) ->
    $scope.user = user
    $scope.userLoading = false
  , ->
    toastr.error 'There has been an error loading the current user!'
    false

and checking the return value in my default error handling I’m able to skip the default behaviour. However from promise.reject() I always get undefined as result, is there a way to achieve this?

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
btiernaycommented, Jan 6, 2017

@mgonto Why not run the local error handlers first, before the global handler? This is how most web frameworks work as it allows the local context to override the default global context.

0reactions
RafaelVidaurrecommented, Jul 28, 2014

I’m having this issue too. I think that the errorInterceptor should somehow be able to tell whether the re’s a reject callback for the promise defined for a particular request. That way we could avoid handling an error if it’s being customly handled somewhere else in our code

A knieve example:

Restangular.setErrorInterceptor(function(response, deferred, rejectCallbackDefined) {
  if (rejectCallbackDefined) {
    // Let the custom error handler do the work
    return true;
  }

  // Default error handling
  // ...
  return false;
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Customizing a Default Error Message (Sun Identity Manager ...
You can customize these default error messages by modifying attributes in the ErrorUIConfig object provided with that message.
Read more >
Create customized error messages for your web page - IU KB
The default configuration is to output a simple hardcoded error message (option 1). Options 2-4 are configured within the .htaccess file.
Read more >
Customize OmniScript Error Messages - Salesforce Help
A default message that returns when no Custom Error Messages are matched or defined. The Default Error Message property is not available in...
Read more >
Customize Error Messages in your Web Applications
There are two ways to add customized error messages: on an application ... select the Default Error Message you wish to customize (in...
Read more >
Customize error messages
You can customize error messages that appear when you launch third party applications. These messages have default content but you may want to...
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