Skip to content

Origin/fix file response exception handling#30

Open
galym-abitech wants to merge 6 commits intoDotNetNomads:masterfrom
galym-abitech:origin/fix_file_response_exception_handling
Open

Origin/fix file response exception handling#30
galym-abitech wants to merge 6 commits intoDotNetNomads:masterfrom
galym-abitech:origin/fix_file_response_exception_handling

Conversation

@galym-abitech
Copy link
Copy Markdown
Contributor

Add File Response exception handling in next api client for properly display error message


private async Task<T> InvokeHttpMessagePack<T>(HttpResponseMessage response)
{
var mediaType = response.Content.Headers.ContentType.MediaType;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is already block with same definitions on lines 305-317. Both InvokeHttpJson and the InvokeHttpMessagePack are being used in InvokeHttp. Perhaps, put this block in a separate method, for example in NextApiUtils, or put it in a calling method InvokeHttp, to not repeat same code over again.

}
default:
throw new Exception($"Unsupported serialization type {HttpSerializationType}");
catch { }
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should throw an exception with type NextApiException, like it been made in line 315.

await connection.StartAsync();
};
connection.On("NextApiEvent", new[] {typeof(NextApiEventMessage)}, ProcessNextApiEvent);
connection.On("NextApiEvent", new[] { typeof(NextApiEventMessage) }, ProcessNextApiEvent);
Copy link
Copy Markdown

@Asiresword Asiresword Apr 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really critical, but it is better to leave it be, or add these whitespaces everywhere to have same code-style. And yet, to get rid of this unnecessary change.

var result = (NextApiResponse)MessagePackSerializer.Typeless.Deserialize(resultByteArray);

if (!result.Success)
{
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is not really critical too, but it is better to get rid of these curly braces to have same code-style everywhere, 'cause NextApi's code style assumes, that single-line conditions will not have them.

string GetCurrentUser();
Task<string> UploadFile(Stream fileStream, string fileName);
Task<NextApiFileResponse> GetFile(string path);
Task<NextApiFileResponse> GetFile(string path, bool throwException = false);
Copy link
Copy Markdown

@Asiresword Asiresword Apr 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, that it is better to add another mock method, instead of modifying existing one, that will have return type of Task<NextApiFileResponse>, will accept only path, and will always throw an exception, if you really need it.
For example: Task<NextApiFileResponse> GetFileException(string path);

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

Successfully merging this pull request may close these issues.

2 participants