Skip to content

Commit 7345bd2

Browse files
committed
1 parent 70c8fa0 commit 7345bd2

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

tp_transcode.c

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ typedef struct {
9898
tp_transcode_t *tc;
9999
} yajl_ctx_t;
100100

101-
static inline char*
101+
static inline char *
102102
tp_call_wof(struct tp *p)
103103
{
104104
int sz = 5 +
@@ -123,7 +123,7 @@ tp_call_wof(struct tp *p)
123123
return tp_add(p, sz);
124124
}
125125

126-
static inline char*
126+
static inline char *
127127
tp_call_wof_add_func(struct tp *p, const char *function, int len)
128128
{
129129
int sz = mp_sizeof_uint(TP_FUNCTION) +
@@ -135,7 +135,7 @@ tp_call_wof_add_func(struct tp *p, const char *function, int len)
135135
return tp_add(p, sz);
136136
}
137137

138-
static inline char*
138+
static inline char *
139139
tp_call_wof_add_params(struct tp *p)
140140
{
141141
int sz = mp_sizeof_uint(TP_TUPLE);
@@ -696,6 +696,24 @@ typedef struct tp2json {
696696
int state;
697697
} tp2json_t;
698698

699+
static inline int
700+
code_conv(int code)
701+
{
702+
switch (code) {
703+
case 0:
704+
break;
705+
case 32801:
706+
code = -32601;
707+
break;
708+
default:
709+
if (code > 0)
710+
code *= -1;
711+
break;
712+
}
713+
714+
return code;
715+
}
716+
699717
static void*
700718
tp2json_create(tp_transcode_t *tc, char *output, size_t output_size)
701719
{
@@ -926,7 +944,7 @@ tp_reply2json_transcode(void *ctx_, const char *in, size_t in_size)
926944
"{\"id\":%zu,\"error\":{\"message\":\"%.*s\",\"code\":%d}",
927945
(size_t)tp_getreqid(&ctx->r),
928946
elen, ctx->r.error,
929-
ctx->r.code);
947+
code_conv(ctx->r.code));
930948

931949
} else {
932950

0 commit comments

Comments
 (0)