
import pecan
from pecan import rest

from solum.api.handlers import assembly_handler
from solum.common import exception


class TriggerController(rest.RestController):
    """Manages triggers."""

    @pecan.expose()
    def post(self, trigger_id):
        """Trigger a new event on Solum."""
        handler = assembly_handler.AssemblyHandler(None)
        try:
            handler.trigger_workflow(trigger_id)
        except exception.ResourceNotFound as excp:
            pecan.response.status = excp.code
            pecan.response.text = excp.message
            return
        pecan.response.status = 202


import pecan
from pecan import rest

from solum.api.handlers import assembly_handler
from solum.common import exception


class TriggerController(rest.RestController):
    """Manages triggers."""

    @pecan.expose()
    def post(self, trigger_id):
        """Trigger a new event on Solum."""
        handler = assembly_handler.AssemblyHandler(None)
        try:
            handler.trigger_workflow(trigger_id)
            pecan.response.status = 202
        except exception.ResourceNotFound as excp:
            pecan.response.status = excp.code
            pecan.response.body = excp.message

Fix pecan error message not available in body for Trigger.post
Fix pecan error message not available in body for Trigger.post

When a trigger_id resource is not found, the API returns a 202 status
code, the error message could not be added in the body of the request
because pecan.response.text was used instead of pecan.response.body.

Change-Id: I8b03210b5a2f2b5c0ea24bfc8149cca122dffeea
Closes-Bug: #1324940

  
  import pecan
  from pecan import rest
  
  from solum.api.handlers import assembly_handler
  from solum.common import exception
  
  
  class TriggerController(rest.RestController):
      """Manages triggers."""
  
      @pecan.expose()
      def post(self, trigger_id):
          """Trigger a new event on Solum."""
          handler = assembly_handler.AssemblyHandler(None)
          try:
              handler.trigger_workflow(trigger_id)
+             pecan.response.status = 202
          except exception.ResourceNotFound as excp:
              pecan.response.status = excp.code
-             pecan.response.text = excp.message
+             pecan.response.body = excp.message
-             return
-         pecan.response.status = 202
  
Fix pecan error message not available in body for Trigger.post
## Code Before:

import pecan
from pecan import rest

from solum.api.handlers import assembly_handler
from solum.common import exception


class TriggerController(rest.RestController):
    """Manages triggers."""

    @pecan.expose()
    def post(self, trigger_id):
        """Trigger a new event on Solum."""
        handler = assembly_handler.AssemblyHandler(None)
        try:
            handler.trigger_workflow(trigger_id)
        except exception.ResourceNotFound as excp:
            pecan.response.status = excp.code
            pecan.response.text = excp.message
            return
        pecan.response.status = 202

## Instruction:
Fix pecan error message not available in body for Trigger.post
## Code After:

import pecan
from pecan import rest

from solum.api.handlers import assembly_handler
from solum.common import exception


class TriggerController(rest.RestController):
    """Manages triggers."""

    @pecan.expose()
    def post(self, trigger_id):
        """Trigger a new event on Solum."""
        handler = assembly_handler.AssemblyHandler(None)
        try:
            handler.trigger_workflow(trigger_id)
            pecan.response.status = 202
        except exception.ResourceNotFound as excp:
            pecan.response.status = excp.code
            pecan.response.body = excp.message
