neocities.h

a C library for interacting with Neocities' API
git clone https://github.com/tanguyandreani/neocities.h
Log | Files | Refs | README | LICENSE

commit ba157c71811151133fde857c99d36028d344f6d2
parent eb2e7abecdad96e2cdc095d99116f628aba9805a
Author: Tanguy Andreani <dev@tanguy.space>
Date:   Sat, 23 Feb 2019 23:39:13 +0100

Added: error messages for api errors

Diffstat:
Minfo.c | 2+-
Mlist.c | 2+-
Mprint_error_msg.h | 22+++++++++++++++++++++-
Mupload.c | 2+-
4 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/info.c b/info.c @@ -35,7 +35,7 @@ int main(int argc, char *argv[]) &res)) != OK || res.result != 0) { neocities_print_error_message(err); if (res.type == NEOCITIES_ERROR_STRUCT) - fprintf(stderr, "error_type: %d\n", res.data.error.type); + neocities_print_error_message_api(res.data.error.type); else neocities_destroy(&res); return err; diff --git a/list.c b/list.c @@ -34,7 +34,7 @@ int main(int argc, char *argv[]) &res)) != OK || res.result != 0) { neocities_print_error_message(err); if (res.type == NEOCITIES_ERROR_STRUCT) - fprintf(stderr, "error_type: %d\n", res.data.error.type); + neocities_print_error_message(res.data.error.type); else neocities_destroy(&res); return err; diff --git a/print_error_msg.h b/print_error_msg.h @@ -1,4 +1,6 @@ -#define M(m) fprintf(stderr, "error %d: " m, err); break +#define M(m) \ + fprintf(stderr, "error %d: " m, err); \ + break void neocities_print_error_message(enum neocities_low_level_error err) { @@ -50,6 +52,8 @@ void neocities_print_error_message(enum neocities_low_level_error err) case NEOCITIES_LLVL_ERR_RECEIVED_SOMETHING_ELSE: M("the type guessed by neocities_json_to_struct() doesn't match" " with the request that was made"); + default: + return; } fputc('\n', stderr); @@ -57,4 +61,20 @@ void neocities_print_error_message(enum neocities_low_level_error err) return; } +void neocities_print_error_message_api(enum neocities_api_level_error err) +{ + switch (err) { + + case SITE_NOT_FOUND: + M("site not found"); + case UNSUPPORTED_ERROR: + M("unknow (yet) error"); + default: + return; + } + fputc('\n', stderr); + + return; +} + #undef M diff --git a/upload.c b/upload.c @@ -43,7 +43,7 @@ int main(int argc, char *argv[]) || res.result != 0) { neocities_print_error_message(err); if (res.type == NEOCITIES_ERROR_STRUCT) - fprintf(stderr, "error_type: %d\n", res.data.error.type); + neocities_print_error_message_api(res.data.error.type); return err; }