Skip to content

Commit

Permalink
Fix #6555: working on _gen_http_exception
Browse files Browse the repository at this point in the history
  • Loading branch information
git-user committed Dec 22, 2023
1 parent 4e66dec commit 81c32ff
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
12 changes: 6 additions & 6 deletions sirepo/package_data/static/js/sirepo-components.js
Original file line number Diff line number Diff line change
Expand Up @@ -4687,11 +4687,8 @@ SIREPO.app.service('fileUpload', function(authState, msgRouter, errorService) {
fd.append(k, args[k]);
}
}
srdbg('authState', authState);
srdbg('file', file);
srdbg('file size = ', file.size);
if (file.size > authState.max_message_bytes) {
callback({error: 'File was too large for upload'});
callback({error: `File of size=${file.size} bytes was too large for upload. Max size=${authState.max_message_bytes} bytes`});
return;
}
//TODO(robnagler) formData needs to be handled properly
Expand All @@ -4701,11 +4698,14 @@ SIREPO.app.service('fileUpload', function(authState, msgRouter, errorService) {
}).then(
function(response) {
srdbg('onSuccess response:', response);
if (response.data.status == 500) {
callback({error: 'File upload failed due to server error'});
return;
}
callback(response.data);
},
function(response) {
srdbg('onRejected response:', response);
callback({error: 'File Upload Failed'});
callback({error: 'File Upload Failed (reason unknown)'});
},
);
};
Expand Down
24 changes: 17 additions & 7 deletions sirepo/reply.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,8 +471,11 @@ def _content():
x = pkcompat.from_bytes(x)
return x, k
elif isinstance(c, _Base):
return c.websocket_content()
res = c.websocket_content()
pkdp("\n\n\n INSTANCE HIT res={}", res)
return res
else:
pkdp("\n\n\n NON INSTANCE HIT. c={} k={}", c, k)
return c, k

async def _send(content, kind):
Expand Down Expand Up @@ -584,13 +587,15 @@ def _gen_exception_reply_SReplyExc(self, args):
return self.from_kwargs(**r.__attrs)

def _gen_exception_reply_ServerError(self, args):
pkdp("\n\n\nreply_serverError hit, args={}", args)
return self._gen_http_exception(500)

def _gen_exception_reply_SPathNotFound(self, args):
pkdlog("uncaught SPathNotFound {}", args)
return self._gen_http_exception(404)

def _gen_exception_reply_SRException(self, args):
pkdp("\n\n\nHIT FOR GEN reply_SRException")
if args.get("params") is None:
args.params = PKDict()
args.pksetdefault(sim_type=lambda: self.qcall.sim_type_uget())
Expand All @@ -610,13 +615,12 @@ def _gen_exception_reply_WWWAuthenticate(self, args):
401, headers=PKDict({"WWW-Authenticate": 'Basic realm="*"'})
)

# def _gen_http_exception(self, code, headers=None):
# return self.from_kwargs(
# content=_HTTPException(PKDict(code=code, headers=headers))
# )
def _gen_http_exception(self, status, headers=None):
pkdp("\n\n\n\nHIT, status={} headers={} \n\n\n\n", status, headers)
return self.from_kwargs(
content=_HTTPException(PKDict(status=status, code=status, headers=headers))
# TODO (gurhar1133): figure out why _HTTPException doesn't work
# but _Object does
content=_Object(PKDict(status=status, code=status, headers=headers))
)

def _gen_redirect_for_anchor(self, uri, **kwargs):
Expand Down Expand Up @@ -704,10 +708,12 @@ def _sr_exception(self, routeName, params, **kwargs):
# certain cases.
# TODO(robnagler) this probably should be an assert
params.pkdel("simulationType")
return (
res = (
PKDict(routeName=routeName, params=params),
sirepo.const.SCHEMA_COMMON.websocketMsg.kind.srException,
)
pkdp("\n\n\n res in _sr_exception = {}", res)
return res

def _value(self, value=None):
return (
Expand All @@ -734,12 +740,15 @@ def websocket_content(self):

class _HTTPException(_Base):
def http_response(self, sreply):
pkdp("\n\n\n hit for http_response")
if self.value.headers:
for k, v in self.value.headers.items():
sreply.header_set(k, v)
return self._http_error(self.value.code, sreply)

def websocket_content(self):
pkdp("\n\n\n hit for websocket_content() \n\n")
pkdp("\n\n\n self.value.code={}", self.value.code)
return self._sr_exception(
routeName="httpException", params=PKDict(code=self.value.code)
)
Expand Down Expand Up @@ -808,4 +817,5 @@ def _sim_type():
)

def websocket_content(self):
pkdp("\n\n\n websocket_content self.value={}", self.value)
return self._sr_exception(**self.value)
1 change: 1 addition & 0 deletions sirepo/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,7 @@ async def api_updateFolder(self):
)
async def api_uploadFile(self, simulation_type, simulation_id, file_type):
# assert 0, "ASSERTION TEST"
# raise sirepo.util.UserAlert("TEST USER ALERT")
f = self.sreq.form_file_get()
req = self.parse_params(
file_type=file_type,
Expand Down

0 comments on commit 81c32ff

Please sign in to comment.