-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from ember-nexus/feature/improve-exception-and…
…-logging Feature/improve exception and logging
- Loading branch information
Showing
138 changed files
with
1,974 additions
and
706 deletions.
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 |
---|---|---|
|
@@ -23,3 +23,6 @@ | |
.phpunit.result.cache | ||
/phpunit.xml | ||
###< symfony/phpunit-bridge ### | ||
|
||
supervisord.log | ||
supervisord.pid |
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
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
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
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
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
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 |
---|---|---|
|
@@ -89,4 +89,4 @@ if [ "$1" = "unitd" ] || [ "$1" = "unitd-debug" ]; then | |
fi | ||
fi | ||
|
||
exec "$@" | ||
exec "$@" |
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,12 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
|
||
mkdir -p /var/www/html/var/logs | ||
touch /var/www/html/var/logs/log.log | ||
|
||
if [ -z "$@" ]; then | ||
supervisord --nodaemon --configuration /etc/supervisord.conf | ||
else | ||
exec "$@" | ||
fi |
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,20 @@ | ||
[supervisord] | ||
nodaemon=true | ||
user=root | ||
|
||
[program:nginx-unit] | ||
command=/usr/local/bin/unit-entrypoint.sh unitd --no-daemon --control unix:/var/run/control.unit.sock | ||
directory=/var/www/html | ||
autostart=true | ||
autorestart=true | ||
stdout_logfile=/dev/stdout | ||
redirect_stderr=true | ||
stdout_logfile_maxbytes=0 | ||
|
||
[program:php-logs] | ||
command=tail -f /var/www/html/var/log/log.log | ||
autostart=true | ||
autorestart=true | ||
stdout_logfile=/dev/stdout | ||
redirect_stderr=true | ||
stdout_logfile_maxbytes=0 |
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
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,66 @@ | ||
# Best Practices | ||
|
||
As Ember Nexus internally uses Symfony, it also uses | ||
[Symfony's best practices](https://symfony.com/doc/current/best_practices.html). | ||
|
||
## Language | ||
|
||
The source code of Ember Nexus and responses generated by Ember Nexus API should be only written in **English**. | ||
|
||
There are two reasons for it: | ||
|
||
- Search engines more easily find exceptions returned in a single language, helping with debugging and general | ||
usability. | ||
- As English is the Lingua Franca of the IT industry, it should be the primary language used in this project. | ||
|
||
Documentations and general user guides should always be available in English, and additional translations or regional | ||
adaptations can be created. | ||
It should be noted that Ember Nexus strives towards long-term stability; i.e., it is better not to support language X | ||
than to shortly abandon language X after trial usage. | ||
|
||
When deciding between using the active vs. passive voice, asking the following question helps: | ||
|
||
> Is it an advantage for the reader to know the performer of the action? | ||
If the answer is Yes, use active voice. If the answer is No, use passive voice. | ||
|
||
See [Technical Writing: Active vs. Passive voice](https://medium.com/@DaphneWatson/technical-writing-active-vs-passive-voice-485dfaa4e498) | ||
for details. | ||
|
||
## Coding Style | ||
|
||
Ember Nexus API tries to implement object-orientated code with patterns where it makes sense. Duplicate code should be | ||
reduced if the code's complexity is similar. | ||
Using easily readable code is better than using the least amount of lines | ||
or highly optimized code. | ||
|
||
Refactoring parts of the source code is always possible as long as code changes are covered by unit tests and existing | ||
feature tests are passed. | ||
|
||
Try to keep the line length below 120 chars. | ||
|
||
## Logging and Exceptions | ||
|
||
Both log messages and exceptions should adhere to a few key principles: | ||
|
||
- Messages should provide context why they are created. | ||
- Messages should provide one specific reason, ideally a unique property or identifier. | ||
- Messages should not contain sensitive data like passwords, hashes, and tokens. | ||
- Messages are sentences, they end with a dot. | ||
|
||
Log messages should be created in the following scenarios: | ||
|
||
- Important events in the lifetime of the API should be documented. This includes startup, shutdown, and backups. | ||
- Security events like creating or updating users, tokens, and sessions should always be logged. If possible, use the | ||
user's unique identifier for context. | ||
- Administrative actions should be fully logged: | ||
- Interactions with the command line. | ||
- Interactions with the API through users with administrative access. | ||
|
||
Exceptions should be created in the following instances: | ||
|
||
- If input validation returns an error. | ||
- If an action is forbidden, likely due to missing security privileges. | ||
- If the requested data does not exist. | ||
- If there is a logic conflict. | ||
- In other problematic instances. |
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,25 @@ | ||
# Exceptions | ||
|
||
List of all exceptions: | ||
|
||
- Internal exceptions: Thrown if there is a problem within the API, 5xx error codes | ||
- External exceptions: Thrown if requests from the client are in any way problematic, 4xx error codes. | ||
- `400-bad-request`: Thrown if user supplied data is bad, incomplete, or problematic. | ||
- `401-unauthorized`: Thrown if supplied token is bad, or anonymous user does not exist. | ||
- `404-not-found`: Default error if data does not exist, or user has no permission to read it. | ||
- `405-method-not-allowed`: Returned if user has READ access, but access to current method. | ||
|
||
| HTTP Status Code | Type | Title | Example Detail (prod) | Example Detail (dev) | | ||
| ---------------- | ----------------------------------------- | ---------------------------- | ------------------------------------------------------------ | ------------------------------------------------------------ | | ||
| 400 | `/error/400/missing-property` | Missing property | Endpoint requires that the request contains property 'x' to be set to Y. | Endpoint requires that the request contains property 'x' to be set to Y. | | ||
| 400 | `/error/400/forbidden-property` | Forbidden Property | Endpoint does not accept setting the property 'x' in the request. | Endpoint does not accept setting the property 'x' in the request. | | ||
| 400 | `/error/400/incomplete-mutual-dependency` | Incomplete mutual dependency | Endpoint has mutual dependency on properties 'x' and 'y'. While property 'x' is set, property 'y' is missing. | Endpoint has mutual dependency on properties 'x' and 'y'. While property 'x' is set, property 'y' is missing. | | ||
| 400 | `/error/400/reserved-identifier` | Reserved identifier | The requested identifier 'x' is reserved and can not be used. | The requested identifier 'x' is reserved and can not be used. | | ||
| 400 | `/error/400/bad-content` | Bad content | Endpoint expects property 'x' to be Y, got 'z'. | Endpoint expects property 'x' to be Y, got 'z'. | | ||
| 401 | `/error/401/unauthorized` | Unauthorized | Request does not contain valid token. | Request does not contain valid token. | | ||
| 404 | `/error/404/not-found` | Not found | Requested element was not found. | Requested element was not found. | | ||
| 405 | `/error/405/method-not-allowed` | Method not allowed | Endpoint does not support requested method, or you do not have sufficient permissions. | Endpoint does not support requested method, or you do not have sufficient permissions. | | ||
| 429 | `/error/429/too-many-requests` | Too many requests | You have sent too many requests, please slow down. | You have sent too many requests, please slow down. | | ||
| 500 | `/error/500/internal-server-error` | Internal server error | Internal server error, see log. | 'error message'. | | ||
| 501 | `/error/501/not-implemented` | Not implemented | Endpoint is currently not implemented. | Endpoint is currently not implemented. | | ||
| 503 | `/error/503/service-unavailable` | Service unavailable | The service itself or an internal component is currently unavailable. | Service 'x' is currently unavailable. | |
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,24 @@ | ||
# Long-Term Plans | ||
|
||
The Ember Nexus API is not intended to be modified or extended by third parties directly - we do not guarantee that | ||
internal code is not refactored or creates breaking changes in minor version updates. | ||
|
||
If you need to handle custom business logic or general automation, then it is recommended to create a separate | ||
web app, which communicates with Ember Nexus over its API, which is stable and will not have breaking changes in minor | ||
version updates. | ||
|
||
## Version 2 of Ember Nexus API | ||
|
||
While no guarantees can be given, we want to experiment if rewriting Ember Nexus API in Rust provides significant | ||
performance benefits. | ||
This experiment starts after the release of version 1.0.0 and will be covered in separate blog | ||
posts. | ||
|
||
The API endpoints of version 2.0, regardless if the API uses Rust or not, will likely be highly similar. | ||
|
||
## Native Support for HTTP 2 / HTTP 3 | ||
|
||
Neither HTTP 2 nor HTTP 3 will be supported during version 1.x. It is recommended to use a reverse proxy like | ||
[Traefik](https://traefik.io/traefik/). | ||
|
||
Support for version 2.x is likely. |
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
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
Oops, something went wrong.