Dijkstra's algorithm in a weighted graph

The Dijkstra's algorithm is never used for a graph with a negative weight. The following graph has negative weight but when the Dijkstra's single source shortest path algorithm run from vertex a, it computes the correct shortest path distance to all the vertices. But when I solve it for the following graph: I am not getting a shortest path, why does the Dijkstra's algorithm working for the first graph and not the other one, or did I make any mistake? Could anyone make me understand it? Run Dijkstra’s algorithm on the graph below considering D as the source vertex, it would make this easier to understand if you also describe the status of the distance array at each iteration.

In the second graph, we can replace each undirected edge with two directed edges. For example we can replace edge between D,C with a directed edge $$D\to C$$ and directed edge $$C\to D$$ such that each edge weight is equal to $$-8$$. This means we have a reachable negative cycle from source, so there is no algorithm to compute shortest path in a such instance of shortest path problem. Because, for example
$$d[D]=-\infty$$.