Skip to content
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

More detailed JSON Decoding error message #24

Open
nashysolutions opened this issue Mar 19, 2023 · 3 comments
Open

More detailed JSON Decoding error message #24

nashysolutions opened this issue Mar 19, 2023 · 3 comments

Comments

@nashysolutions
Copy link

The feedback for corrupt or unexpected data is lacking.

struct EditPoll: Codable, Equatable {
    let name: String
    let description: String
    let duration: Int
    let roomId: UUID
}

Route(.case(PollsRoute.create)) {
    Method.post
    Body(.json(EditPoll.self))
}

error: The data couldn’t be read because it isn’t in the correct format.

I think the following would print more specific information.

print(String(describing: jsonDecodingError))
``
@saroar
Copy link

saroar commented Apr 27, 2023

hi did you fixed it same issue I am getting some work some not

@stephencelis
Copy link
Member

@nashysolutions @saroar Can you flesh this issue out if you think you're experiencing a bug? A specific reproduction would be helpful for us to work with.

@nashysolutions
Copy link
Author

Sorry for late response @stephencelis

For any given body

let usersRoute = OneOf {
        
    Route(.case(UsersRoute.create)) {
        Method.post
        Body(.json(UserCandidate.self))
    }

If UserCandidate does not match the expected payload exactly, and decoding fails.

public struct UserCandidate: Codable {
    
    public let firstName: String // should be name, not firstName
    public let username: String
    public let password: String

Then the response is unhelpful.

error: The data couldn’t be read because it is missing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants