ssossossosso

Forums

Covering OroCRM topics, including community updates and company announcements.  Subscribe

Forums OroPlatform Custom Error Messages in the Flash Message

This topic contains 7 replies, has 3 voices, and was last updated by  zhex900 6 months, 3 weeks ago.

  • Creator
    Topic
  • #63408

    zhex900
    Participant

    Hi,
    How do I create a customer error message? I want it to stop the application and display the error message in the flash message.

    Jake He

Viewing 7 replies - 1 through 7 (of 7 total)
  • Author
    Replies
  • #63409

    mmiasnikov
    Moderator

    Hi, Jake!

    Actually, it depends on where do you want to create an error message. You have following options, for example:

    1) You, of course, always have a regular Symfony-based ability to throw flash messages from Session. In controllers, particularly, you can use addFlash() method for this (please, see the Symfony’s “Controller” documentation article)

    2) In Oro Workflows (and processes) you can use “@flash_message” action:

    For detailed examples, please, look for “@flash_message” usages in workflow definitions in Oro bundles.

    Regards!


    #63410

    zhex900
    Participant

    Hi,

    Thank you for your reply.

    I want to throw an error message in a custom class I had. This is what I done.
    1) Inject session into my class
    2) $this->session->getFlashBag()->add(‘error’, ‘Calendar does not exist.’);

    However this error message is not displayed.

    Jake He

    #63411

    zhex900
    Participant

    What I want is to throw an exception like throw new \Exception( 'Calendar does not exist.');
    I want this exception message to be displayed in the flash message. So replacing Error: Unexpected content format with ‘Calendar does not exist.’

    Screen_Shot_2017_08_01_at_4_58_46_pm

    #63412

    Yurii Muratov
    Participant

    Hi, @zhex900. Very strange that you does not see your message from the $this->session->getFlashBag()->add(‘error’, ‘Calendar does not exist.’);. I gust tested your case and all works for me.

    Please see, maybe you have some JS error.

    About the message from the exception. As for me it is not very good idea to send error messages as flash message because user should have translated message that will describe what was going wrong.

    #63413

    zhex900
    Participant

    Error: Unexpected content format flash message displayed first. After I go another page like contacts. Calendar does not exist flash message comes up.

    I want to stop the app and display an error message. Like validation.

    #63414

    zhex900
    Participant

    Hi,

    I know what the problem is. The session service I injected is null. But how do I fix it?

    #63415

    zhex900
    Participant

    I found a work around. I throw an exception and catch it at the class that calls it.

Viewing 7 replies - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.

ssossossosso