diff options
Diffstat (limited to 'error.c')
-rw-r--r-- | error.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/error.c b/error.c new file mode 100644 index 0000000..1f51455 --- /dev/null +++ b/error.c @@ -0,0 +1,32 @@ +#include <errno.h> +#include "error.h" + +int error_http_status(enum sternenblog_error err) { + switch(err) { + case STERNENBLOG_OK: + return 200; + case STERNENBLOG_ERROR_NOT_FOUND: + return 404; + case STERNENBLOG_ERROR_FORBIDDEN: + return 403; + case STERNENBLOG_ERROR_REQUEST: + return 400; + case STERNENBLOG_ERROR_SYSTEM: + case STERNENBLOG_ERROR_CGI: + case STERNENBLOG_ERROR_UNEXPECTED: + default: + return 500; + } +} + +int error_from_errno(void) { + switch(errno) { + case EPERM: + case EACCES: + return STERNENBLOG_ERROR_FORBIDDEN; + case ENOENT: + return STERNENBLOG_ERROR_NOT_FOUND; + default: + return STERNENBLOG_ERROR_SYSTEM; + } +} |