-
Notifications
You must be signed in to change notification settings - Fork 801
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
08a15f8
commit b08848b
Showing
2 changed files
with
45 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
============= | ||
Error Handling | ||
============= | ||
BentoML allows user to define custom error handling logic for their Service. | ||
|
||
This document describes how to define a custom exception class and error handling logic in a BentoML Service. | ||
|
||
Custom Exception Class | ||
----------------------- | ||
User can define custom exception class by inheriting from `BentoMLException` or any of its subclasses, such as `InvalidArgument` in the example below. | ||
|
||
.. note:: | ||
|
||
Error Code 401, 403, and >500 is reserved by BentoML, user should not use these error codes in their custom exception class. | ||
|
||
.. code-block:: python | ||
import bentoml | ||
from bentoml.exceptions import InvalidArgument, BentoMLException | ||
from http import HTTPStatus | ||
class MyCustomException(BentoMLException): | ||
error_code = HTTPStatus.METHOD_NOT_ALLOWED | ||
class MyCustomInvalidArgsException(InvalidArgument): | ||
pass | ||
@bentoml.service | ||
class MyService: | ||
@bentoml.api | ||
def test1(self, text: str) -> str: | ||
raise MyCustomException("this is a custom error message") | ||
@bentoml.api | ||
def test2(self, text: str) -> str: | ||
raise MyCustomInvalidArgsException("this is a custom error message") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters