Skip to content

Commit

Permalink
Merge pull request #159 from twirphp/fix-meta-serialization
Browse files Browse the repository at this point in the history
Fix meta serialization
  • Loading branch information
sagikazarmark authored May 17, 2024
2 parents 125fd57 + f7c7877 commit 00bc36b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"Tests\\Twirp\\": "lib/tests/",
"Twirp\\Example\\": "example/src/",
"": [
"example/generated/",
"tests/clientcompat/generated/",
"tests/complete/generated/",
"tests/namespace/generated/"
Expand Down
11 changes: 8 additions & 3 deletions protoc-gen-twirp_php/templates/service/Server.php.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -331,11 +331,16 @@ final class {{ .Service | phpServiceName .File }}Server implements RequestHandle
$e = TwirpError::errorFrom($e, 'internal error');
}

$body = $this->streamFactory->createStream(json_encode([
$rawBody = [
'code' => $e->getErrorCode(),
'msg' => $e->getMessage(),
'meta' => $e->getMetaMap(),
]));
];

if (!empty($e->getMetaMap())) {
$rawBody['meta'] = $e->getMetaMap();
}

$body = $this->streamFactory->createStream(json_encode($rawBody, \JSON_FORCE_OBJECT));

return $this->responseFactory
->createResponse($statusCode)
Expand Down

0 comments on commit 00bc36b

Please sign in to comment.