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

get site stats API result in 500 when website_id is wrong #1252

Closed
boly38 opened this issue Jul 2, 2022 · 3 comments
Closed

get site stats API result in 500 when website_id is wrong #1252

boly38 opened this issue Jul 2, 2022 · 3 comments
Labels
enhancement New feature or request stale

Comments

@boly38
Copy link

boly38 commented Jul 2, 2022

(not exactly the same as #1241 but very close)

by error I set undefinedas website ID and the following query
GET https://umami.mydomain.com/api/website/undefined/stats

results in 500 Internal Server Error with folliwing stack from docker

PrismaClientValidationError: Argument website_id: Got invalid value NaN on prisma.findUniquewebsite. Provided Float, expected Int.

   at Object.validate (/app/node_modules/@prisma/client/runtime/index.js:44374:20)
   at PrismaClient._executeRequest (/app/node_modules/@prisma/client/runtime/index.js:46458:17)
   at consumer (/app/node_modules/@prisma/client/runtime/index.js:46402:23)
   at /app/node_modules/@prisma/client/runtime/index.js:46406:76
   at runInChildSpan (/app/node_modules/@prisma/client/runtime/index.js:45651:12)
   at /app/node_modules/@prisma/client/runtime/index.js:46406:20
   at AsyncResource.runInAsyncScope (async_hooks.js:189:9)
   at PrismaClient._request (/app/node_modules/@prisma/client/runtime/index.js:46405:86)
   at /app/node_modules/@prisma/client/runtime/index.js:43037:25
   at _callback (/app/node_modules/@prisma/client/runtime/index.js:42801:52) {
 clientVersion: '3.12.0'
}

next with a valid website_id, I got
GET https://umami.mydomain.com/api/website/2/stats

results in 500 Internal Server Error with folliwing stack from docker

PrismaClientKnownRequestError: Failed to validate the query: `Assertion error: Nested JSON arguments are not supported.` at `Mutation.queryRaw.parameters`
    at Object.request (/app/node_modules/@prisma/client/runtime/index.js:45578:15) {
  code: 'P2009',
  clientVersion: '3.12.0',
  meta: {
    query_validation_error: 'Assertion error: Nested JSON arguments are not supported.',
    query_position: 'Mutation.queryRaw.parameters'
  }
}

next with a valid website_id, and period
GET https://umami.mydomain.com/api/website/2/stats?start_at=1656679719687&end_at=1656766119687

I got success

{
  pageviews: { value: 3, change: 3 },
  uniques: { value: 1, change: 1 },
  bounces: { value: 0, change: 0 },
  totaltime: { value: 2, change: 2 }
}

here is the way to build query

  const start_at = Date.now()  - (60000 * 60 * 24); // now - 24h
  const end_at = Date.now();
  // const statsUrl = serverUrl+ `/api/website/${siteData.website_id}/stats?start_at=${start_at}&end_at=${end_at}`;
  const statsUrl = serverUrl+ `/api/website/${siteData.website_id}/stats?` + querystring.stringify({ start_at, end_at });

what did I expect from this issue:

  • for an invalid pathParam (ex:website_id) or queryParam (ex: start_at) : a 400 InvalidParameter error response with friendly user detailed message: what is wrong in my query, how to fix it if relevant.
  • for online documentation, a little sample. And more details on format : ex. timestamp in milliseconds.

NB: for umami user; using developer console, you could inspect network exchange from umami portal to have an idea of what param (or param format) are expected for some umami API if documentation is not complete.

@itodouble
Copy link

get http://umami.domain/api/website/undefined/stats

1|umami  | warn  - using beta Middleware (not covered by semver) - https://nextjs.org/docs/messages/beta-middleware
1|umami  | PrismaClientValidationError: Argument website_id: Got invalid value NaN on prisma.findUniquewebsite. Provided Float, expected Int.
1|umami  |     at Object.validate (/data/www/umami/node_modules/@prisma/client/runtime/index.js:44201:20)
1|umami  |     at PrismaClient._executeRequest (/data/www/umami/node_modules/@prisma/client/runtime/index.js:46354:17)
1|umami  |     at consumer (/data/www/umami/node_modules/@prisma/client/runtime/index.js:46298:23)
1|umami  |     at /data/www/umami/node_modules/@prisma/client/runtime/index.js:46302:76
1|umami  |     at runInChildSpan (/data/www/umami/node_modules/@prisma/client/runtime/index.js:45510:12)
1|umami  |     at /data/www/umami/node_modules/@prisma/client/runtime/index.js:46302:20
1|umami  |     at AsyncResource.runInAsyncScope (node:async_hooks:202:9)
1|umami  |     at PrismaClient._request (/data/www/umami/node_modules/@prisma/client/runtime/index.js:46301:86)
1|umami  |     at /data/www/umami/node_modules/@prisma/client/runtime/index.js:42862:25
1|umami  |     at _callback (/data/www/umami/node_modules/@prisma/client/runtime/index.js:42626:52) {
1|umami  |   clientVersion: '3.14.0'
1|umami  | }

@github-actions
Copy link

This issue is stale because it has been open for 60 days with no activity.

@github-actions github-actions bot added the stale label Aug 19, 2023
@github-actions
Copy link

This issue was closed because it has been inactive for 7 days since being marked as stale.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Aug 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request stale
Projects
None yet
Development

No branches or pull requests

3 participants