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

How to obtain backend error messages, And that are not displayed in the console? #766

Open
evilpose opened this issue Oct 17, 2024 · 3 comments

Comments

@evilpose
Copy link

evilpose commented Oct 17, 2024

I want to be able to proactively capture this error, so that it is not displayed in the console, but in the form of a UI on the page. I couldn't find a similar hook, can you help me check this problem?

image
image

export const createLanguageClient = (
  transports: MessageTransports,
): MonacoLanguageClient => {
  return new MonacoLanguageClient({
    name: 'xxx Language Client',
    clientOptions: {
      documentSelector: ['isogql'],
      errorHandler: {
        error: () => ({ action: ErrorAction.Continue }),
        closed: () => ({ action: CloseAction.Restart }),
      },
    },
    connectionProvider: {
      get: () => {
        return Promise.resolve(transports);
      },
    },
  });
};

export const createWebSocket = (url: string): WebSocket => {
  const webSocket = new WebSocket(url);
  webSocket.onopen = () => {
    const socket = toSocket(webSocket);
    const reader = new WebSocketMessageReader(socket);
    const writer = new WebSocketMessageWriter(socket);
    const languageClient = createLanguageClient({
      reader,
      writer,
    });
    languageClient.start();
    reader.onClose(() => {
      createWebSocket(url);
    });
  };
  return webSocket;
};


@CGNonofr
Copy link
Collaborator

You can probably replace the Log/Logger service override with you custom impl. The default one logs to the console

@CGNonofr
Copy link
Collaborator

I've answered too fast! It's an UnexpectedError, the code allows to override the handler but the libs don't expose it, fixing that

@CGNonofr
Copy link
Collaborator

with CodinGame/monaco-vscode-api#513, you'll be able to do

import { setUnexpectedErrorHandler } from 'vscode/monaco'

setUnexpectedErrorHandler((e) => {
  // whatever you want
})

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

2 participants