From 71a358001cee5ac557512a12918ea6ca95b17570 Mon Sep 17 00:00:00 2001 From: "me@ow.nekobit.net" Date: Wed, 27 Apr 2022 18:36:50 +0000 Subject: [PATCH] Handle multiple errors (somewhat) FossilOrigin-Name: 2145b0a4409a8f4d6eb5e999b2c7275a34f20a7dede06fddd6f8d360aed765b9 --- Makefile | 2 +- src/error.c | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 0779721..d2f648c 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC ?= cc -CFLAGS = -g -ansi -Wall -Werror=implicit-function-declaration -I ./include/ +CFLAGS = -g -ansi -Wall -Werror=implicit-function-declaration -I ./include/ `pkg-config --cflags libcjson` SRC = $(wildcard src/*.c) OBJ = $(patsubst %.c,%.o,$(SRC)) TARGET = libmastodont.a # shared diff --git a/src/error.c b/src/error.c index f234202..3adedfe 100644 --- a/src/error.c +++ b/src/error.c @@ -16,6 +16,18 @@ #include #include +static void _mstdnt_val_errors_call(cJSON* v, void* _type) +{ + char** type = _type; + if (v->child && v->child->valuestring) + *type = v->child->valuestring; + else + { + *type = NULL; + return; + } +} + int mstdnt_check_error(struct mstdnt_fetch_results* results, struct mstdnt_storage* storage) { @@ -28,8 +40,10 @@ int mstdnt_check_error(struct mstdnt_fetch_results* results, storage->error = NULL; storage->error_description = NULL; + /* TODO I have no idea why multiple errors can be returned */ struct _mstdnt_val_ref refs[] = { { "error", &(storage->error), _mstdnt_val_string_call }, + { "errors", &(storage->error), _mstdnt_val_errors_call }, { "error_description", &(storage->error_description), _mstdnt_val_string_call }, };