add optional `opts` object

Allow to pass an optional "opts" argument that gets added to the error object.