Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recipe for using Foyle endpoints with if/else #236

Open
jlewi opened this issue Sep 13, 2024 · 1 comment
Open

Recipe for using Foyle endpoints with if/else #236

jlewi opened this issue Sep 13, 2024 · 1 comment

Comments

@jlewi
Copy link
Owner

jlewi commented Sep 13, 2024

Our playbooks rely on using CURL to hit various endpoints. We often pipe the output to jq for further processing

export TRACEID=$(curl -s -X POST http://localhost:8877/api/foyle.logs.LogsService/GetBlockLog -H "Content-Type: application/json" -d "{\"id\": \"${CELLID}\"}" | jq .blockLog.genTraceId)

The problem with this is that it doesn't play well with the case where the request fails or returns an error. In which case we should abort rather than piping to jq.

So I think we need to use an if/else statement. But what's a good recipe for testing whether it succeeded?

@jlewi
Copy link
Owner Author

jlewi commented Sep 13, 2024

One pattern could be to do

  1. Write output to a file
  2. Check the exit code
    e.g.
curl -s -o /tmp/response.json -X POST http://localhost:8877/api/foyle.logs.LogsService/GetLLMLogs -H "Content-Type: application/json" -d "{\"traceId\": \"${TRACEID}\"}"
CODE="$?"
if [ $CODE -ne 0 ]; then
  echo "Error occurred while fetching LLM logs"
  exit $CODE
fi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant