-
Notifications
You must be signed in to change notification settings - Fork 16
Open
Description
Description
When attempting to use sparse fieldsets for an invalid type, a 500 is raised. Is this the correct functionality? I would think this is more of a 400 level error. To demonstrate, if one were to make a request for GET /cars?fields[dealership]=name using the code below, they would get the documented 500 response. I would be happy to open a PR to change this functionality if there is agreement that there is a better way to handle these errors (i.e. raise 4XX error).
Problematic Code
| raise Exception("Couldn't find schema for type: {}".format(resource_type)) |
Example
# Example
class Car(Base):
id = Column(Int, primary_key=True)
make = Column(Str)
model = Column(Str)
class CarSchema
class Meta:
type_ = "car"
make = fields.Str()
model = fields.Str()
class CarListResource(ResourceList):
methods = ["GET"]
schema = CarSchema
data_layer = {"session": db.session, "model": Car}
app = Flask(__name__)
api = Api(app)
api.route(
CarListResource, "car_resource", "/cars",
)Example Response
// GET /cars?fields[dealership]=name`
// status code: 500
{
"errors": [
{
"status": "500",
"title": "Unknown error",
"detail": "Couldn't find schema for type: dealership"
}
],
"jsonapi": {
"version": "1.0"
}
}Metadata
Metadata
Assignees
Labels
No labels