makenotion / notion-sdk-js

Official Notion JavaScript Client
https://developers.notion.com/docs
MIT License
4.94k stars 590 forks source link

UnknownHTTPResponseError: Request to Notion API failed with status: 502 #457

Open britonmarketing opened 1 year ago

britonmarketing commented 1 year ago

This one is a duplicate of https://github.com/makenotion/notion-sdk-js/issues/172, it occurs for many users and needs to be re-open

Server Error UnknownHTTPResponseError: Request to Notion API failed with status: 502

This error happened while generating the page. Any console logs will be displayed in the terminal window.

I have about 30 pages, it occurs randomly on a few of them during the build

Console:

Uncaught UnknownHTTPResponseError: Request to Notion API failed with status: 502 at buildRequestError at Client.request at process.processTicksAndRejections at async getProps at async Object.renderToHTML at async doRender at async cacheEntry1.responseCache.get.incrementalCache.incrementalCache at async

interpolack commented 1 year ago

thanks for opening. adding my name to the list of people it's happening to

lailo commented 1 year ago

I've been experiencing this issue for a few days while collecting page data in my Next.js app. It used to occur randomly and only occasionally, but now it happens every time.

@notionhq/client warn: request fail {
   code: 'notionhq_client_response_error',
   message: 'Request to Notion API failed with status: 502'
}
michalpuchmertl commented 1 year ago

Same for me.

Badestrand commented 1 year ago

same and from #172 it seems to be a really prevalent issue.

DZGoldman commented 1 year ago

same - hadn't seen this error before but now hitting it consistently

AlAgilly commented 1 year ago

Same. It even occurs for just reading small databases (~15 pages). It's reoccurring at an increasing amount the past week.. Error:

@notionhq/client warn: request fail {
  code: 'notionhq_client_response_error',
  message: 'Request to Notion API failed with status: 502'
}

My code can be found here: https://github.com/AlAgilly/yues_website/blob/main/server/index.js

Willing to give access to my databases if needed

stensrud commented 1 year ago

I'm getting the same problem

lakeesiv commented 1 year ago

Im also getting this aswell

accounts01 commented 1 year ago

+1. I'm experiencing this as well.

BenMt commented 1 year ago

+1

juanicortesl commented 1 year ago

+1

ziegfried commented 1 year ago

The main problem here is that the notion client holds on to the connection and once it hits a 502 error, every subsequent request also results in such an error. Even creating a new notion client instance doesn't solve the issue (it uses the same http agent instance).

Our current workaround:

Something along the lines:

import { Agent } from "https";
import { Client } from "@notionhq/client";

let agent, notion;

function reset() {
    if (agent) agent.destroy();
    agent = new Agent();
    notion = new Client({ auth: process.env.NOTION_TOKEN, agent });
}

reset();

// Using the notion client:
try {
    // do something with notion client
} catch(e) {
    const errorText = e.toString();
    if (
      errorText.includes("PgPoolWaitConnectionTimeout") ||
      errorText.includes("Request timed out") ||
      errorText.includes("Request to Notion API has timed out") ||
      errorText.includes("Request to Notion API failed with status: 502")
    ) {
      reset();
    }
}
Badestrand commented 1 year ago

I now also get the error

@notionhq/client warn: request fail {
  code: 'service_unavailable',
  message: 'Request timed out waiting to connect to a database. Please try again later.'
}

sometimes.

TopherTimeMachine commented 1 year ago

I just starting getting this message while trying to create a page. It was working a few days ago.

@notionhq/client warn: request fail {
  code: 'notionhq_client_request_timeout',
  message: 'Request to Notion API has timed out'
}

I tried the reset() solution above and didn't seem to work. What other options are there? Notion support or dev team listening in?

pulbyte commented 1 year ago

I am getting both these errors, almost 50% of time while GET:/ notion page, While updating a notion page, While querying a Notion database.

@notionhq/client warn: request fail {
 code: 'notionhq_client_request_timeout',
 message: 'Request to Notion API has timed out'
}

@notionhq/client warn: request fail {
 code: 'notionhq_client_response_error',
 message: 'Request to Notion API failed with status: 502'
}

Although retrying works, But It's still not viable solution and Notion API has almost become unreliable recently.

NodeJs version : 20 @notionhq/client": "^2.2.7"

remihuigen commented 1 year ago

Same here! Just contacted support, since i don't think they are gonna respond to this github issue. Will post update if I get a response

Smidgens commented 1 year ago

I'm still getting this occasionally on reads, with no discernible pattern (reads of any size, random hours...). My workaround is to simply catch the error and retry. So far I think it's always succeeded on the second try but...

It would be great if Notion either added a mention of 502s to the API docs, or silently handled the error in the SDK (make it an opt-in flag even).

remihuigen commented 1 year ago

Same here! Just contacted support, since i don't think they are gonna respond to this github issue. Will post update if I get a response

Just got a reply from support:

I can understand how important this is for you and the inconvenience this created to your workflow.   In the last couple of days, Notion and API experienced incidents with degraded performance. I'm happy to inform you that this has now been resolved!   You should be good to go! :)

In the last 24 hours I've only occasionally encountered 502s, but they are still popping up now and then. I also don't buy Notion supports claim that it has been 'an issue in the last couple of days' and that it should be resolved now. Since as far as I can tell the 502s have been happening for over two weeks.

Anyway, I believe they are still not willing to acknowledge the shabby state of their public API, and we should not except any improvements soon. My conclusion is that their API is fun for internal projects, but not production ready anytime soon.

I've implemented a workaround where the app retries fetching the API if the response is a 502, with a max of 5 retries. So far I haven't needed the fifth retry.

linkyndy commented 1 year ago

Same issue here, only that every requests times out or takes >20s to respond. Basically, we cannot use the API. And we haven't heard back on any of our tickets on any of the support channels about this.

DerickIT commented 6 months ago

I still have this problem. Can I solve it in other ways?

mxro commented 6 days ago

Would this be the correct way to catch it?

import { UnknownHTTPResponseError } from '@notionhq/client';

    try {
      return await notionOperation();
    } catch (er) {
      if (
        (er instanceof UnknownHTTPResponseError && er.status === 502) ||
      ) {
        // do retry logic
    }

But I guess this should be added to the 'known' error types since seems quite common:

https://github.com/makenotion/notion-sdk-js/blob/main/src/errors.ts#L9

wongww commented 8 hours ago

Still an issue in 2024.

Moein-Bam commented 5 hours ago

Everything worked last week. It fails today with this error.

@notionhq/client warn: request fail {
  code: "notionhq_client_response_error",
  message: "Request to Notion API failed with status: 502",
}

Update: I retried the job, and I no longer get this error. It was probably resolved by Notion from the backend side.
The error is back. I have no idea what causes it.