polyphony/sonata
9
15
Fork
You've already forked sonata
5

feat: Errors returned as JSON #8

Merged
ava merged 2 commits from Guinness/sonata:feat/error-middleware into main 2025年09月05日 18:40:56 +02:00
Contributor
Copy link

This commit implements an error handler as a middleware.

For now it handles ParseJsonError with a specific case and the rest of
the errors are json serialized.

.-(17:02:09)-(~)------------------------------------------------------------------------------(neha@vali)-
`---> curl -d '{"tosConsent":false}' -H "Content-Type: application/json" -X POST localhost:3011/.p2/auth/register
{"cause":"parse error: missing field `localName` at line 1 column 20","error":"ParseJsonError"}% 
.-(17:06:07)-(~)------------------------------------------------------------------------------(neha@vali)-
`---> curl -H "Content-Type: application/json" -X POST http://localhost:3011/.p2/auth/register
{"cause":"parse error: EOF while parsing a value at line 1 column 0","error":"ParseJsonError"}% 

Fixes #2

This commit implements an error handler as a middleware. For now it handles ParseJsonError with a specific case and the rest of the errors are json serialized. ``` .-(17:02:09)-(~)------------------------------------------------------------------------------(neha@vali)- `---> curl -d '{"tosConsent":false}' -H "Content-Type: application/json" -X POST localhost:3011/.p2/auth/register {"cause":"parse error: missing field `localName` at line 1 column 20","error":"ParseJsonError"}% .-(17:06:07)-(~)------------------------------------------------------------------------------(neha@vali)- `---> curl -H "Content-Type: application/json" -X POST http://localhost:3011/.p2/auth/register {"cause":"parse error: EOF while parsing a value at line 1 column 0","error":"ParseJsonError"}% ``` Fixes https://codeberg.org/polyphony/sonata/issues/2
This commit implements an error handler as a middleware.
For now it handles ParseJsonError with a specific case and the rest of
the errors are json serialized.
ava requested changes 2025年09月05日 18:33:33 +02:00
Dismissed
ava left a comment
Copy link

Just the tiniest change request, but thank you for this PR! :)

Just the tiniest change request, but thank you for this PR! :)
@ -62,0 +89,4 @@
asyncfn call(&self,req: poem::Request)-> poem::Result<Self::Output>{
letresp=self.ep.call(req).await;
matchresp{
Ok(_resp)=>Ok(_resp.into_response()),
Owner
Copy link
Ok(resp) => Ok(resp.into_response()),

Since the binding is used, the underscore is no longer useful

```suggestion Ok(resp) => Ok(resp.into_response()), ``` Since the binding is used, the underscore is no longer useful
ava marked this conversation as resolved
ava approved these changes 2025年09月05日 18:40:16 +02:00
Owner
Copy link

Thank you a lot for your time and effort! ^^ The PR is very appreciated :)

Thank you a lot for your time and effort! ^^ The PR is very appreciated :)
Sign in to join this conversation.
No reviewers
ava
Labels
Clear labels
Difficulty: Complex

Archived

Difficulty: Easy

Archived

Difficulty: Medium

Archived

Difficulty: Trivial

Archived

Difficulty: what

Archived

Priority: Critical

Archived

Priority: High

Archived

Priority: Low

Archived

Priority: Medium

Archived

Status: Abandoned

Archived

Status: Accepted

Archived

Status: Available

Archived

Status: Blocked

Archived

Status: Completed

Archived

Status: In Progress

Archived

Status: On Hold

Archived

Status: Pending

Archived

Status: Review Needed

Archived

Status: Revision Needed

Archived

Type: Bug

Archived

Type: Enhancement

Archived

Type: Maintenance

Archived

Type: Question

Archived

⚠️Priority
A (Highest)
Highest priority issue
⚠️Priority
C (High)
High priority issue
⚠️Priority
D (Medium-High)
Medium to high priority issue
⚠️Priority
E (Medium)
Medium priority issue
⚠️Priority
G (Low)
Low priority issue
⚠️Priority
H (Lowest)
Lowest priority issue
🏷️Kind
Bug
Something is not as expected. For specifications or guidelines, an under-/overspecification is also considered a bug.
🏷️Kind
Chore
Regular maintainance tasks, version bumps, lint fixes
🏷️Kind
Documentation
Documentation changes
🏷️Kind
Epic
This issue is a collection of other, related issues.
🏷️Kind
Feature
New functionality
🏷️Kind
Improvement
Improve existing functionality
🏷️Kind
Task
A specific work item. Can be part of an epic
🏷️Kind
Testing and CI
Change related to CI or testing
👁️Reviewed
Duplicate
This issue or pull request already exists
👁️Reviewed
Invalid
Invalid issue
👁️Reviewed
Valid
This issue has been reviewed and a resolution is desired
👁️Reviewed
Won't Fix
This issue won't be fixed
📋️Kind/Security
This is security issue

Archived

📋️Status
Abandoned
Somebody has started to work on this but abandoned work
📋️Status
Blocked
Something is blocking this issue or pull request

Archived

📋️Status
In Progress
This label is intended to be used when an outside collaborator is pursuing the completion of this issue, since they cannot be directly assigned to the task.
📋️Status
Need More Info
Feedback is required to reproduce issue or to continue work
🔧Difficulty
A (Very hard)
Measure of time-to-implement and cognitive complexity of the task. "Hard" tasks usually take >15h to complete. Extremely unlikely to be suitable for first-time-contributors.
🔧Difficulty
B (Hard)
Measure of time-to-implement and cognitive complexity of the task. "Hard" tasks usually take 3h-15h to complete. Very likely not suitable for first-time-contributors.
🔧Difficulty
C (Medium)
Measure of time-to-implement and cognitive complexity of the task. "Medium" tasks usually take 30min-3h to complete. Likely not suitable for first-time-contributors.
🔧Difficulty
D (Easy)
Measure of time-to-implement and cognitive complexity of the task. "Easy" tasks usually take 15-30min to complete. Likely suitable for first-time-contributors.
🔧Difficulty
E (Trivial)
Measure of time-to-implement and cognitive complexity of the task. "Trivial" tasks usually take 1-15min to complete. Very likely suitable for first-time-contributors.
Compat
Breaking
Breaking change that won't be backward compatible
Good First Issue
This issue is a good task to take on if you are new to the project or the repository and looking to contribute.
No labels
Difficulty: Complex
Difficulty: Easy
Difficulty: Medium
Difficulty: Trivial
Difficulty: what
Priority: Critical
Priority: High
Priority: Low
Priority: Medium
Status: Abandoned
Status: Accepted
Status: Available
Status: Blocked
Status: Completed
Status: In Progress
Status: On Hold
Status: Pending
Status: Review Needed
Status: Revision Needed
Type: Bug
Type: Enhancement
Type: Maintenance
Type: Question
⚠️Priority
A (Highest)
⚠️Priority
C (High)
⚠️Priority
D (Medium-High)
⚠️Priority
E (Medium)
⚠️Priority
G (Low)
⚠️Priority
H (Lowest)
🏷️Kind
Bug
🏷️Kind
Chore
🏷️Kind
Documentation
🏷️Kind
Epic
🏷️Kind
Feature
🏷️Kind
Improvement
🏷️Kind
Task
🏷️Kind
Testing and CI
👁️Reviewed
Duplicate
👁️Reviewed
Invalid
👁️Reviewed
Valid
👁️Reviewed
Won't Fix
📋️Kind/Security
📋️Status
Abandoned
📋️Status
Blocked
📋️Status
In Progress
📋️Status
Need More Info
🔧Difficulty
A (Very hard)
🔧Difficulty
B (Hard)
🔧Difficulty
C (Medium)
🔧Difficulty
D (Easy)
🔧Difficulty
E (Trivial)
Compat
Breaking
Good First Issue
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
polyphony/sonata!8
Reference in a new issue
polyphony/sonata
No description provided.
Delete branch "Guinness/sonata:feat/error-middleware"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?