OroPlatform Forums

Covering OroPlatform topics, including community updates and company announcements.

Forums Forums OroPlatform Custom Error Messages in the Flash Message

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

Starting from March 1, 2020 the forum has been switched to the read-only mode. Please head to StackOverflow for support.

  • Creator
    Topic
  • #37046

    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
  • #37047

    mmiasnikov
    Participant

    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!

    #37048

    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

    #37049

    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

    #37050

    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.

    #37051

    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.

    #37052

    zhex900
    Participant

    Hi,

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

    #37053

    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)

The forum ‘OroPlatform’ is closed to new topics and replies.

Back to top