Handle Solr error messages from Blacklight - ruby-on-rails

Whenever Solr fails executing a query for some reason it returns an error message and an error code. I would like to handle such errors in Blacklight. Right now, when receiving an error from Solr, the user gets a 500 internal error. As a developer I can see that what happens is an RSolr::Error::Http in CatalogController#index with the following line of code as the source of the problem:
res = blacklight_solr.send_and_receive(path, :params=>solr_params)
Is it possible to customize the error handling so that I can at least display an indicative error message to the user instead of the unhelpful 500 internal error?

Open file lib\blacklight\catalog.rb. The function rsolr_request_error(exception) is responsible to handle Solr errors. The exception parameter is an RSolr::RequestError and it represents the error from Solr. In order to handle the error by displaying the message from Solr just add the following inside the else:
error_status = eval(exception.response[:body])['error']
if !error_status.nil? and !error_status['msg'].nil?
flash_notice = error_status['msg']
else
flash_notice = I18n.t('blacklight.search.errors.request_error')
end
If you wish to display a different message then assign a different message to flash_notice. If you wish to handle the error differently then this is where to do so.

Related

Custom error message is not showed in the app

In the restful app I am implementing error handling, but I cannot see the error message being displayed in the frontend UI. Instead, I only see a different error message from the framework.
Although I can see that my custom error message error message being propagated to the frontend it appears to be subsequently overwritten with a different message from the framework.
So I am not sure if this is something with the versions I work with (ABAP-1909 and UI5-1.96.12) or it is my implementation issue.
Implementation type: Unmanaged scenario.
ABAP version: S/4 Hana On Prem 1909
UI5 Version: '1.107.1'
Code snippet:
APPEND VALUE #( %cid = <fs_lsi_create>-%cid
uuid = ls_lsi_crt-uuid
) TO failed-incidents.
APPEND VALUE #(
%cid = <fs_lsi_create>-%cid
%key-uuid = ls_lsi_crt-uuid
%msg = new_message( id = 'ZLSAPP_MSG'
number = 001
severity = if_abap_behv_message=>severity-error
v1 = <fs_lsi_create>-name )
uuid = ls_lsi_crt-uuid ) TO reported-incidents.
I was expecting to see the error message in a popup on the frontend application, but I see it only in the debugger console, it doesn't appear in the error popup screen.

Is there a list of JSON parse error codes?

I'm trying to provide a good experience to users that are using JSON and the parser is on the backend (Ruby).
Most of the time, when you get a badly formatted JSON payload the error is of the format XXX unexpected token at '<entire payload here>'. That's not very user-friendly nor practical.
My question is: Is there a list of the XXX error codes that could help create better error messages that could be understood by beginners and not-really-tech-people?
Thanks!
XXX in this kind of errors is not a special code of the error. It is just a line number from the file where this error was raised. For example, for Ruby 2.5.1 you'll get JSON::ParserError (765: unexpected token at https://github.com/ruby/ruby/blob/v2_5_1/ext/json/parser/parser.rl#L765
You can find a list in the documentation for the module.
Think this covers it:
JSON::JSONError
JSON::GeneratorError
JSON::GenericObject
# The base exception for JSON errors.
JSON::MissingUnicodeSupport
# This exception is raised if the required unicode support is missing on the system. Usually this means that the iconv library is not installed.
JSON::NestingError
# This exception is raised if the nesting of parsed data structures is too deep.
JSON::ParserError
# This exception is raised if a parser error occurs.
JSON::UnparserError
# This exception is raised if a generator or unparser error occurs.
JSON::JSONError is the parent class, so you can rescue from that and provide per-error-class messages as needed.
I feel it's worth noting that in my experience the vast majority of errors relating to JSON are of the class JSON::ParserError. Another common issue worth considering is getting ArgumentError if nil is passed as an argument.
As an example of how this could be used, you could work with something like the following:
begin
JSON.parse(your_json)
rescue JSON::JSONError, ArgumentError => e
{ error: I18n.t(e.to_s) } # <- or whatever you want to do per error
end
Hope that helps - let me know how you get on :)

On production server at one page I am getting Fatal error ActionView::Template::Error

I am getting this error " ActionView::Template::Error (bad component(expected host component): ): ", on research on stackoverflow I observed this error is occurring on wrong config of mailer. But I have not configured any mails.
From the details shared , the first line indicates error in fetching the data.
A line of action to resolve this could be,
first to check the correctness of data fetch using rails console/sandbox environment.
Once point 1 above is sorted out and still error, then have a look at the view and check the rendering/flow.
This will point you to the error.

quickfix/j NewOrderMultileg message get truncated

In my application, I am receiving a NewOrderMultiLeg message. The entire message is logged into the 'messages.log' file. But when I recevie the message into the onMessage(Message message, SessionID sessionID) method, I am getting only a part of the message, the message is getting truncated. i.e I only one element from the repeated group and the rest of the messages are truncated. I pasted here the message I recevied in log file and method.
Please help me to sort out this issue.
Message from application debugger.
8=FIX.4.49=10935=AB34=749=Server52=20150525-07:10:47.05956=TRADERINFO1=0.011=1250000163=1110=0228=0555=3635=0.010=075
Message from FIX logger.
8=FIX.4.49=24735=AB49=Server56=XXXXXXX34=452=20150525-07:08:14.71111=125000011=0.063=1635=0.0110=0228=0555=3616=9623=1687=10565=1616=3623=1687=10565=1616=13623=1687=10565=160=20150525-07:08:09.874152=1040=2376=XXXXXXXSERVER835=310=229
I am using FIX 4.4, quickfixj1.5.3.
Part of my config file
RejectInvalidMessage=N
ValidateFieldsHaveValues=N
ValidateIncomingMessage=N
ValidateFieldsOutOfOrder=N
ValidateUserDefinedFields=N
DefaultApplVerID=FIX.4.4
UseDataDictionary=Y
Thanks in advance.
Thanks
Bibin
I was missing one mandatory field 'LegSymbol' in InstrumentLeg component. In QuickFIX/J FIX4.4 dictionary shows 'LegSymbol' is non mandatory field but I found from some other sources, it is a mandatory field. Once I started receving the message with 'LegSymbol' field, my issues got sorted out.
Thanks
Bibin

Weird rails error while loading the application

I am having this bizarre error and I don't know what to do.
This code runs fine on my development and staging machine but crashes on production.
All I have to do is load the page or call script/server to trigger the following error:
Error message:
interning empty string
Exception class:
ArgumentError
Full Stack trace: Code
Sorry for this short description, but this is all that i am able to show to you. =/
Thank you.
This could be because you have an invalid filename for a partial (a filename with two consecutive zeros).
For example
_partial..html.erb (invalid)
This blog post mentions this error:
http://anaphoral.blogspot.com/2009/04/rails-interning-empty-string.html

Resources