Skip to content

Refactored to unbound on_error methods when accessing outer app.py va… #385

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Nov 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions samples/05.multi-turn-prompt/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import asyncio
import sys
from datetime import datetime
from types import MethodType

from flask import Flask, request, Response
from botbuilder.core import (
Expand Down Expand Up @@ -59,7 +58,9 @@ async def on_error(context: TurnContext, error: Exception):
# Clear out state
await CONVERSATION_STATE.delete(context)

ADAPTER.on_turn_error = MethodType(on_error, ADAPTER)
# Set the error handler on the Adapter.
# In this case, we want an unbound method, so MethodType is not needed.
ADAPTER.on_turn_error = on_error

# Create MemoryStorage, UserState and ConversationState
MEMORY = MemoryStorage()
Expand Down
7 changes: 4 additions & 3 deletions samples/06.using-cards/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import asyncio
import sys
from datetime import datetime
from types import MethodType

from flask import Flask, request, Response
from botbuilder.core import (
Expand Down Expand Up @@ -35,7 +34,7 @@


# Catch-all for errors.
async def on_error(self, context: TurnContext, error: Exception):
async def on_error(context: TurnContext, error: Exception):
# This check writes out errors to console log .vs. app insights.
# NOTE: In production environment, you should consider logging this to Azure
# application insights.
Expand All @@ -61,7 +60,9 @@ async def on_error(self, context: TurnContext, error: Exception):
# Clear out state
await CONVERSATION_STATE.delete(context)

ADAPTER.on_turn_error = MethodType(on_error, ADAPTER)
# Set the error handler on the Adapter.
# In this case, we want an unbound method, so MethodType is not needed.
ADAPTER.on_turn_error = on_error

# Create MemoryStorage, UserState and ConversationState
MEMORY = MemoryStorage()
Expand Down
8 changes: 4 additions & 4 deletions samples/21.corebot-app-insights/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import asyncio
import sys
from datetime import datetime
from types import MethodType

from flask import Flask, request, Response
from botbuilder.core import (
Expand Down Expand Up @@ -45,7 +44,7 @@


# Catch-all for errors.
async def on_error(self, context: TurnContext, error: Exception):
async def on_error(context: TurnContext, error: Exception):
# This check writes out errors to console log .vs. app insights.
# NOTE: In production environment, you should consider logging this to Azure
# application insights.
Expand All @@ -69,10 +68,11 @@ async def on_error(self, context: TurnContext, error: Exception):
await context.send_activity(trace_activity)

# Clear out state
nonlocal self
await CONVERSATION_STATE.delete(context)

ADAPTER.on_turn_error = MethodType(on_error, ADAPTER)
# Set the error handler on the Adapter.
# In this case, we want an unbound method, so MethodType is not needed.
ADAPTER.on_turn_error = on_error

# Create MemoryStorage, UserState and ConversationState
MEMORY = MemoryStorage()
Expand Down
7 changes: 4 additions & 3 deletions samples/44.prompt-users-for-input/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import asyncio
import sys
from datetime import datetime
from types import MethodType

from flask import Flask, request, Response
from botbuilder.core import (
Expand All @@ -31,7 +30,7 @@


# Catch-all for errors.
async def on_error(self, context: TurnContext, error: Exception):
async def on_error(context: TurnContext, error: Exception):
# This check writes out errors to console log .vs. app insights.
# NOTE: In production environment, you should consider logging this to Azure
# application insights.
Expand All @@ -57,7 +56,9 @@ async def on_error(self, context: TurnContext, error: Exception):
# Clear out state
await CONVERSATION_STATE.delete(context)

ADAPTER.on_turn_error = MethodType(on_error, ADAPTER)
# Set the error handler on the Adapter.
# In this case, we want an unbound method, so MethodType is not needed.
ADAPTER.on_turn_error = on_error

# Create MemoryStorage and state
MEMORY = MemoryStorage()
Expand Down
7 changes: 4 additions & 3 deletions samples/45.state-management/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import asyncio
import sys
from datetime import datetime
from types import MethodType

from flask import Flask, request, Response
from botbuilder.core import (
Expand All @@ -31,7 +30,7 @@


# Catch-all for errors.
async def on_error(self, context: TurnContext, error: Exception):
async def on_error(context: TurnContext, error: Exception):
# This check writes out errors to console log .vs. app insights.
# NOTE: In production environment, you should consider logging this to Azure
# application insights.
Expand All @@ -57,7 +56,9 @@ async def on_error(self, context: TurnContext, error: Exception):
# Clear out state
await CONVERSATION_STATE.delete(context)

ADAPTER.on_turn_error = MethodType(on_error, ADAPTER)
# Set the error handler on the Adapter.
# In this case, we want an unbound method, so MethodType is not needed.
ADAPTER.on_turn_error = on_error

# Create MemoryStorage and state
MEMORY = MemoryStorage()
Expand Down