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

Build a custom logger #67

Open
juliusmarminge opened this issue Apr 22, 2022 · 4 comments
Open

Build a custom logger #67

juliusmarminge opened this issue Apr 22, 2022 · 4 comments
Labels
enhancement New feature or request wontfix This will not be worked on

Comments

@juliusmarminge
Copy link
Collaborator

The API's current logging system is quite all over the place. different errors are reported in their own structure, some examples are

# /api/<version>/sensors/[id]
400: { formErrors: [], fieldErrors: { id: ["Required."] } }
404: { message: "Sensor with sensor id 1 not found." }
500: { error: "Internal server error." }

The suggestion is to have the logger report errors that are structured the same way, perhaps:

400: { code: "sensors/id_required", message: "A required parameter `id` was not provided." }
404: { code: "sensors/not_found", message: "Could not find a sensor with id 1" }
500: { code: "server_error" message: <An actual representation of what went wrong> }
@juliusmarminge juliusmarminge added the enhancement New feature or request label Apr 22, 2022
@andreas-bauer
Copy link
Member

I don't like the idea of having a code field inside of the return structure.
The standardized HTTP status code should be used to describe the type of response/error.
An additional code field doens't provide enough value to justify the maintenance overhead with custom codes.
Custom codes need to be documented and an consitent use through the whole application must be ensured.

I would suggest having a message field that the describes the problem good and using the standardized HTTP status codes. If a good message is not enough you could add an error field that contains everything that a try-catch-block catched as error message. But I'm not sure if this is really needed. As always, keep it simple until you really need it.

{
"message" : "Good description of the problem",
"error": "error message that is catched from another func call" // not sure if really needed
}

@juliusmarminge
Copy link
Collaborator Author

Yes this was not something I meant should be implementerad now. The error messages are good and often clearly tells what went wrong.

The problem now is simply that all errors are formatted differently which doesnt adhere to the "design-cheat-sheet" you sent us: https://r.bluethl.net/how-to-design-better-apis#heading-10-use-standardized-error-responses

@andreas-bauer
Copy link
Member

Hi, I understood that you want to uniform the error respones and I agree on that.
My point is, that in your proposal you have the field code: "sensors/id_required" which itself is not a good idea since it doesn't provide any value and is redundant with the HTTP status code and the URL for the ressource.

@juliusmarminge
Copy link
Collaborator Author

Okay, got you! The format I proposed came straight from that guide I linked previously.

The format is something you could finalize later. The implementation of this logger is not in our backlog for this project, perhaps a later group can take this on another time.

@juliusmarminge juliusmarminge added the wontfix This will not be worked on label Apr 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants