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

Send errors on PUT after stream is returned #115

Open
bredar opened this issue Oct 21, 2022 · 2 comments
Open

Send errors on PUT after stream is returned #115

bredar opened this issue Oct 21, 2022 · 2 comments

Comments

@bredar
Copy link

bredar commented Oct 21, 2022

We have to do some actions, after a file is uploaded. This actions can fail. How to send an error to WebDAV in this case?

protected _openWriteStream(
		path: WebDav.Path,
		ctx: WebDav.OpenWriteStreamInfo,
		callback: WebDav.ReturnCallback<Writable>
	): void {
      const  stream = createWriteStream('c:\upload', 'binary'); 
      stream.on('finish', async () => {
          // move file and stuff
          // -> how to raise an error so http 500 is sent?
     }
     callback(undefined, stream);
);
@ViktorMasnyi
Copy link

@bredar try to pass the instance of Error as first argument of callback:
callback(error, stream)

@bredar
Copy link
Author

bredar commented Dec 5, 2023

Problem is, first we do need to return the stream to allow uploading. Therefore the callback without the error was called already. The potential error we need to catch and return is after that, in the finish section. Calling the callback again with an error does not have an effect.

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